jba 3/21/91

This commit is contained in:
Janet B. Anderson
1991-03-22 15:19:06 +00:00
parent a6339fb924
commit b2ccd32adf
34 changed files with 811 additions and 995 deletions

View File

@@ -41,6 +41,7 @@ struct {
/* control block for callback*/
struct callback {
void (*callback)();
int priority;
struct dbAddr dbAddr;
WDOG_ID wd_id;
void (*process)();
@@ -73,6 +74,7 @@ static long init_record(pai,process)
pcallback = (struct callback *)(calloc(1,sizeof(struct callback)));
pai->dpvt = (caddr_t)pcallback;
pcallback->callback = myCallback;
pcallback->priority = priorityLow;
if(dbNameToAddr(pai->name,&(pcallback->dbAddr))) {
logMsg("dbNameToAddr failed in init_record for devAiTestAsyn\n");
exit(1);
@@ -96,7 +98,7 @@ static long read_ai(pai)
char message[100];
long status,options,nRequest;
struct callback *pcallback=(struct callback *)(pai->dpvt);
short wait_time;
int wait_time;
/* ai.inp must be a CONSTANT*/
switch (pai->inp.type) {
@@ -105,7 +107,7 @@ static long read_ai(pai)
printf("%s Completed\n",pai->name);
return(0); /* don`t convert*/
} else {
wait_time = (short)(pai->rval * vxTicksPerSecond);
wait_time = (int)(pai->rval * vxTicksPerSecond);
if(wait_time<=0) return(0);
printf("%s Starting asynchronous processing\n",pai->name);
wdStart(pcallback->wd_id,wait_time,callbackRequest,pcallback);

View File

@@ -92,7 +92,7 @@ static long write_ao(pao)
pao->nsta = SOFT_ALARM;
if(pao->stat!=SOFT_ALARM) {
strcpy(message,pao->name);
strcat(message,": devAoSoft (write_ao) Illegal INP field");
strcat(message,": devAoSoft (write_ao) Illegal OUT field");
errMessage(S_db_badField,message);
}
}

View File

@@ -107,7 +107,7 @@ static long special_linconv(pao,after)
pao->eslo = (pao->eguf -pao->egul)/4095.0;
return(0);
}
static void read_ao(pao)
struct aoRecord *pao;
{
@@ -116,15 +116,7 @@ struct aoRecord *pao;
/* get the value from the ao driver */
ao_read(pvmeio->card,pvmeio->signal,VMI4100,&value);
/* convert raw readback to egu */
switch (pao->linr){
case (LINEAR):
pao->rbv = (value * pao->eslo) + pao->egul;
break;
default:
pao->rbv = value;
}
pao->val = pao->rbv;
pao->rbv = pao->rval = value;
return;
}

View File

@@ -35,26 +35,19 @@ struct {
init_record,
NULL,
read_bi};
static long masks[] = {
0x00000001,0x00000002,0x00000004,0x00000008,
0x00000010,0x00000020,0x00000040,0x00000080,
0x00000100,0x00000200,0x00000400,0x00000800,
0x00001000,0x00002000,0x00004000,0x00008000,
0x00010000,0x00020000,0x00040000,0x00080000,
0x00100000,0x00200000,0x00400000,0x00800000,
0x01000000,0x02000000,0x04000000,0x08000000,
0x10000000,0x20000000,0x40000000,0x80000000,
};
static long init_record(pbi)
struct biRecord *pbi;
{
char message[100];
struct vmeio *pvmeio;
/* bi.inp must be an VME_IO */
switch (pbi->inp.type) {
case (VME_IO) :
pvmeio = (struct vmeio *)&(pbi->inp.value);
pbi->mask=1;
pbi->mask <<= pvmeio->signal;
break;
default :
strcpy(message,pbi->name);
@@ -64,7 +57,7 @@ static long init_record(pbi)
}
return(0);
}
static long read_bi(pbi)
struct biRecord *pbi;
{
@@ -74,16 +67,15 @@ static long read_bi(pbi)
pvmeio = (struct vmeio *)&(pbi->inp.value);
status = bi_driver(pvmeio->card,masks[pvmeio->signal],BB910,&value);
status = bi_driver(pvmeio->card,pbi->mask,BB910,&value);
if(status==0) {
pbi->rval = value;
if(value == 0) pbi->val = 0;
else pbi->val = 1;
return(0);
} else {
if(pbi->nsev<MAJOR_ALARM ) {
if(pbi->nsev<VALID_ALARM ) {
pbi->nsta = READ_ALARM;
pbi->nsev = MAJOR_ALARM;
pbi->nsev = VALID_ALARM;
}
return(2);
}
return(status);
}

View File

@@ -67,7 +67,6 @@ static long read_bi(pbi)
{
char message[100];
long status,options,nRequest;
unsigned short val;
/* bi.inp must be a CONSTANT or a DB_LINK or a CA_LINK*/
switch (pbi->inp.type) {
@@ -77,17 +76,14 @@ static long read_bi(pbi)
options=0;
nRequest=1;
status = dbGetLink(&(pbi->inp.value.db_link),pbi,DBR_USHORT,
&val,&options,&nRequest);
&pbi->val,&options,&nRequest);
if(status!=0) {
if(pbi->nsev<VALID_ALARM) {
pbi->nsev = VALID_ALARM;
pbi->nsta = LINK_ALARM;
}
return(2);
}
else {
if (val==0) pbi->val = 0;
else pbi->val = 1;
}
break;
case (CA_LINK) :
break;
@@ -102,5 +98,5 @@ static long read_bi(pbi)
}
}
}
return(0);
return(2);
}

View File

@@ -1,7 +1,7 @@
/* devBiSoft.c */
/* devBiSoftRaw.c */
/* share/src/dev $Id$ */
/* devBiSoft.c - Device Support Routines for Soft Binary Input*/
/* devBiSoftRaw.c - Device Support Routines for Soft Binary Input*/
#include <vxWorks.h>
@@ -17,7 +17,7 @@
#include <biRecord.h>
/* Create the dset for devBiSoft */
/* Create the dset for devBiSoftRaw */
long init_record();
long read_bi();
@@ -28,7 +28,7 @@ struct {
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;
}devBiSoft={
}devBiSoftRaw={
5,
NULL,
NULL,
@@ -45,7 +45,7 @@ static long init_record(pbi)
/* bi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pbi->inp.type) {
case (CONSTANT) :
pbi->val = pbi->inp.value.value;
pbi->rval = pbi->inp.value.value;
break;
case (PV_LINK) :
break;
@@ -55,7 +55,7 @@ static long init_record(pbi)
break;
default :
strcpy(message,pbi->name);
strcat(message,": devBiSoft (init_record) Illegal INP field");
strcat(message,": devBiSoftRaw (init_record) Illegal INP field");
errMessage(S_db_badField,message);
return(S_db_badField);
}
@@ -67,7 +67,6 @@ static long read_bi(pbi)
{
char message[100];
long status,options,nRequest;
unsigned short val;
/* bi.inp must be a CONSTANT or a DB_LINK or a CA_LINK*/
switch (pbi->inp.type) {
@@ -76,8 +75,8 @@ static long read_bi(pbi)
case (DB_LINK) :
options=0;
nRequest=1;
status = dbGetLink(&(pbi->inp.value.db_link),pbi,DBR_USHORT,
&val,&options,&nRequest);
status = dbGetLink(&(pbi->inp.value.db_link),pbi,DBR_ULONG,
&pbi->rval,&options,&nRequest);
if(status!=0) {
if(pbi->nsev<VALID_ALARM) {
pbi->nsev = VALID_ALARM;
@@ -94,7 +93,7 @@ static long read_bi(pbi)
pbi->nsta = SOFT_ALARM;
if(pbi->stat!=SOFT_ALARM) {
strcpy(message,pbi->name);
strcat(message,": devBiSoft (read_bi) Illegal INP field");
strcat(message,": devBiSoftRaw (read_bi) Illegal INP field");
errMessage(S_db_badField,message);
}
}

View File

@@ -35,26 +35,19 @@ struct {
init_record,
NULL,
read_bi};
static long masks[] = {
0x00000001,0x00000002,0x00000004,0x00000008,
0x00000010,0x00000020,0x00000040,0x00000080,
0x00000100,0x00000200,0x00000400,0x00000800,
0x00001000,0x00002000,0x00004000,0x00008000,
0x00010000,0x00020000,0x00040000,0x00080000,
0x00100000,0x00200000,0x00400000,0x00800000,
0x01000000,0x02000000,0x04000000,0x08000000,
0x10000000,0x20000000,0x40000000,0x80000000,
};
static long init_record(pbi)
struct biRecord *pbi;
{
char message[100];
struct vmeio *pvmeio;
/* bi.inp must be an VME_IO */
switch (pbi->inp.type) {
case (VME_IO) :
pvmeio = (struct vmeio *)&(pbi->inp.value);
pbi->mask=1;
pbi->mask <<= pvmeio->signal;
break;
default :
strcpy(message,pbi->name);
@@ -64,7 +57,7 @@ static long init_record(pbi)
}
return(0);
}
static long read_bi(pbi)
struct biRecord *pbi;
{
@@ -74,16 +67,16 @@ static long read_bi(pbi)
pvmeio = (struct vmeio *)&(pbi->inp.value);
status = bi_driver(pvmeio->card,masks[pvmeio->signal],XY210,&value);
status = bi_driver(pvmeio->card,pbi->mask,XY210,&value);
if(status==0) {
pbi->rval = value;
if(value == 0) pbi->val = 0;
else pbi->val = 1;
return(0);
} else {
if(pbi->nsev<MAJOR_ALARM ) {
if(pbi->nsev<VALID_ALARM ) {
pbi->nsta = READ_ALARM;
pbi->nsev = MAJOR_ALARM;
pbi->nsev = VALID_ALARM;
}
return(2);
}
return(status);
}

View File

@@ -35,18 +35,7 @@ struct {
init_record,
NULL,
write_bo};
static long masks[] = {
0x00000001,0x00000002,0x00000004,0x00000008,
0x00000010,0x00000020,0x00000040,0x00000080,
0x00000100,0x00000200,0x00000400,0x00000800,
0x00001000,0x00002000,0x00004000,0x00008000,
0x00010000,0x00020000,0x00040000,0x00080000,
0x00100000,0x00200000,0x00400000,0x00800000,
0x01000000,0x02000000,0x04000000,0x08000000,
0x10000000,0x20000000,0x40000000,0x80000000,
};
static long init_record(pbo)
struct boRecord *pbo;
{
@@ -58,10 +47,12 @@ static long init_record(pbo)
switch (pbo->out.type) {
case (VME_IO) :
pvmeio = (struct vmeio *)(&pbo->out.value);
pbo->mask = 1;
pbo->mask <<= pvmeio->signal;
/* read the value via bo driver */
status = bo_read(pvmeio->card,masks[pvmeio->signal],&value,BB902);
status = bo_read(pvmeio->card,pbo->mask,&value,BB902);
if(status == 0) {
pbo->rbv = pbo->val = (value == 0)?0:1;
pbo->rval = value;
} else if(status == -1) {
strcpy(message,pbo->name);
strcat(message,": devBoMpv902 (init_record) card does not exist");
@@ -82,7 +73,7 @@ static long init_record(pbo)
}
return(0);
}
static long write_bo(pbo)
struct boRecord *pbo;
{
@@ -91,9 +82,7 @@ static long write_bo(pbo)
pvmeio = (struct vmeio *)&(pbo->out.value);
if(pbo->val == 0) pbo->rval = 0;
else pbo->rval = masks[pvmeio->signal];
status = bo_driver(pvmeio->card,pbo->rval,masks[pvmeio->signal],BB902);
status = bo_driver(pvmeio->card,pbo->rval,pbo->mask,BB902);
if(status!=0) {
if(pbo->nsev<MAJOR_ALARM ) {
pbo->nsta = WRITE_ALARM;

View File

@@ -36,7 +36,6 @@ struct {
NULL,
write_bo};
static long init_record(pbo)
struct boRecord *pbo;
{
@@ -60,7 +59,7 @@ static long init_record(pbo)
}
return(0);
}
static long write_bo(pbo)
struct boRecord *pbo;
{

View File

@@ -35,32 +35,24 @@ struct {
init_record,
NULL,
write_bo};
static long masks[] = {
0x00000001,0x00000002,0x00000004,0x00000008,
0x00000010,0x00000020,0x00000040,0x00000080,
0x00000100,0x00000200,0x00000400,0x00000800,
0x00001000,0x00002000,0x00004000,0x00008000,
0x00010000,0x00020000,0x00040000,0x00080000,
0x00100000,0x00200000,0x00400000,0x00800000,
0x01000000,0x02000000,0x04000000,0x08000000,
0x10000000,0x20000000,0x40000000,0x80000000,
};
static long init_record(pbo)
struct boRecord *pbo;
{
char message[100];
int value,status;
unsigned int value;
int status;
struct vmeio *pvmeio;
/* bo.out must be an VME_IO */
switch (pbo->out.type) {
case (VME_IO) :
pvmeio = (struct vmeio *)&(pbo->out.value);
status = bo_read(pvmeio->card,masks[pvmeio->signal],&value,XY220);
pbo->mask = 1;
pbo->mask <<= pvmeio->signal;
status = bo_read(pvmeio->card,pbo->mask,&value,XY220);
if(status == 0) {
pbo->rbv = pbo->val = (value == 0)?0:1;
pbo->rval = value;
} else if(status == -1) {
strcpy(message,pbo->name);
strcat(message,": devBoXVme220 (init_record) card does not exist");
@@ -81,7 +73,7 @@ static long init_record(pbo)
}
return(0);
}
static long write_bo(pbo)
struct boRecord *pbo;
{
@@ -90,9 +82,7 @@ static long write_bo(pbo)
pvmeio = (struct vmeio *)&(pbo->out.value);
if(pbo->val == 0) pbo->rval = 0;
else pbo->rval = masks[pvmeio->signal];
status = bo_driver(pvmeio->card,pbo->rval,masks[pvmeio->signal],XY220);
status = bo_driver(pvmeio->card,pbo->rval,pbo->mask,XY220);
if(status!=0) {
if(pbo->nsev<MAJOR_ALARM ) {
pbo->nsta = WRITE_ALARM;

View File

@@ -36,19 +36,7 @@ struct {
init_record,
NULL,
read_mbbi};
static long masks[] = {
0x00000000,
0x00000001, 0x00000003, 0x00000007, 0x0000000f,
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff
};
static long init_record(pmbbi)
struct mbbiRecord *pmbbi;
{
@@ -57,7 +45,8 @@ static long init_record(pmbbi)
/* mbbi.inp must be an VME_IO */
switch (pmbbi->inp.type) {
case (VME_IO) :
pmbbi->mask = masks[pmbbi->nobt]<<pmbbi->inp.value.vmeio.signal;
pmbbi->shft = pmbbi->inp.value.vmeio.signal;
pmbbi->mask <<= pmbbi->shft;
break;
default :
strcpy(message,pmbbi->name);
@@ -67,7 +56,7 @@ static long init_record(pmbbi)
}
return(0);
}
static long read_mbbi(pmbbi)
struct mbbiRecord *pmbbi;
{
@@ -79,7 +68,7 @@ static long read_mbbi(pmbbi)
pvmeio = (struct vmeio *)&(pmbbi->inp.value);
status = bi_driver(pvmeio->card,pmbbi->mask,BB910,&value);
if(status==0) {
pmbbi->rval = value >> pvmeio->signal;
pmbbi->rval = value;
} else {
if(pmbbi->nsev<MAJOR_ALARM ) {
pmbbi->nsta = READ_ALARM;

View File

@@ -75,8 +75,8 @@ static long read_mbbi(pmbbi)
case (DB_LINK) :
options=0;
nRequest=1;
status = dbGetLink(&(pmbbi->inp.value.db_link),pmbbi,DBR_ULONG,
&(pmbbi->rval),&options,&nRequest);
status = dbGetLink(&(pmbbi->inp.value.db_link),pmbbi,DBR_USHORT,
&(pmbbi->val),&options,&nRequest);
if(status!=0) {
if(pmbbi->nsev<VALID_ALARM) {
pmbbi->nsev = VALID_ALARM;

View File

@@ -1,7 +1,8 @@
/* devBiSoft.c */
/* share/src/dev @(#)devBiSoftRaw.c 1.1 3/20/91 */
/* devBiSoft.c - Device Support Routines for Soft Binary Input*/
/* devMbbiSoftRaw.c */
/* share/src/dev $Id$ */
/* devMbbiSoftRaw.c - Device Support Routines for Soft Multibit Binary Input*/
#include <vxWorks.h>
@@ -14,12 +15,12 @@
#include <devSup.h>
#include <link.h>
#include <module_types.h>
#include <biRecord.h>
#include <mbbiRecord.h>
/* Create the dset for devBiSoft */
/* Create the dset for devMbbiSoftRaw */
long init_record();
long read_bi();
long read_mbbi();
struct {
long number;
@@ -27,25 +28,24 @@ struct {
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;
}devBiSoft={
DEVSUPFUN read_mbbi;
}devMbbiSoftRaw={
5,
NULL,
NULL,
init_record,
NULL,
read_bi};
read_mbbi};
static long init_record(pbi)
struct biRecord *pbi;
static long init_record(pmbbi)
struct mbbiRecord *pmbbi;
{
char message[100];
/* bi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pbi->inp.type) {
/* mbbi.inp must be a CONSTANT or a PV_LINK or a DB_LINK or a CA_LINK*/
switch (pmbbi->inp.type) {
case (CONSTANT) :
pbi->val = pbi->inp.value.value;
pmbbi->rval = pmbbi->inp.value.value;
break;
case (PV_LINK) :
break;
@@ -54,34 +54,34 @@ static long init_record(pbi)
case (CA_LINK) :
break;
default :
strcpy(message,pbi->name);
strcat(message,": devBiSoft (init_record) Illegal INP field");
strcpy(message,pmbbi->name);
strcat(message,": devMbbiSoftRaw (init_record) Illegal INP field");
errMessage(S_db_badField,message);
return(S_db_badField);
}
return(0);
}
static long read_bi(pbi)
struct biRecord *pbi;
static long read_mbbi(pmbbi)
struct mbbiRecord *pmbbi;
{
char message[100];
long status,options,nRequest;
unsigned short val;
/* bi.inp must be a CONSTANT or a DB_LINK or a CA_LINK*/
switch (pbi->inp.type) {
/* mbbi.inp must be a CONSTANT or a DB_LINK or a CA_LINK*/
switch (pmbbi->inp.type) {
case (CONSTANT) :
return(2);
break;
case (DB_LINK) :
options=0;
nRequest=1;
status = dbGetLink(&(pbi->inp.value.db_link),pbi,DBR_USHORT,
&val,&options,&nRequest);
status = dbGetLink(&(pmbbi->inp.value.db_link),pmbbi,DBR_ULONG,
&(pmbbi->rval),&options,&nRequest);
if(status!=0) {
if(pbi->nsev<VALID_ALARM) {
pbi->nsev = VALID_ALARM;
pbi->nsta = LINK_ALARM;
if(pmbbi->nsev<VALID_ALARM) {
pmbbi->nsev = VALID_ALARM;
pmbbi->nsta = LINK_ALARM;
}
return(2);
}
@@ -89,15 +89,16 @@ static long read_bi(pbi)
case (CA_LINK) :
break;
default :
if(pbi->nsev<MAJOR_ALARM) {
pbi->nsev = MAJOR_ALARM;
pbi->nsta = SOFT_ALARM;
if(pbi->stat!=SOFT_ALARM) {
strcpy(message,pbi->name);
strcat(message,": devBiSoft (read_bi) Illegal INP field");
if(pmbbi->nsev<MAJOR_ALARM) {
pmbbi->nsev = MAJOR_ALARM;
pmbbi->nsta = SOFT_ALARM;
if(pmbbi->stat!=SOFT_ALARM) {
strcpy(message,pmbbi->name);
strcat(message,": devMbbiSoftRaw (read_mbbi) Illegal INP field");
errMessage(S_db_badField,message);
}
}
return(2);
}
return(2);
return(0);
}

View File

@@ -36,19 +36,7 @@ struct {
init_record,
NULL,
read_mbbi};
static long masks[] = {
0x00000000,
0x00000001, 0x00000003, 0x00000007, 0x0000000f,
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff
};
static long init_record(pmbbi)
struct mbbiRecord *pmbbi;
{
@@ -57,7 +45,8 @@ static long init_record(pmbbi)
/* mbbi.inp must be an VME_IO */
switch (pmbbi->inp.type) {
case (VME_IO) :
pmbbi->mask = masks[pmbbi->nobt]<<pmbbi->inp.value.vmeio.signal;
pmbbi->shft = pmbbi->inp.value.vmeio.signal;
pmbbi->mask <<= pmbbi->shft;
break;
default :
strcpy(message,pmbbi->name);
@@ -67,7 +56,7 @@ static long init_record(pmbbi)
}
return(0);
}
static long read_mbbi(pmbbi)
struct mbbiRecord *pmbbi;
{
@@ -79,7 +68,7 @@ static long read_mbbi(pmbbi)
pvmeio = (struct vmeio *)&(pmbbi->inp.value);
status = bi_driver(pvmeio->card,pmbbi->mask,XY210,&value);
if(status==0) {
pmbbi->rval = value >> pvmeio->signal;
pmbbi->rval = value;
} else {
if(pmbbi->nsev<MAJOR_ALARM ) {
pmbbi->nsta = READ_ALARM;

View File

@@ -36,19 +36,7 @@ struct {
init_record,
NULL,
write_mbbo};
static long masks[] = {
0x00000000,
0x00000001, 0x00000003, 0x00000007, 0x0000000f,
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff
};
static long init_record(pmbbo)
struct mbboRecord *pmbbo;
{
@@ -61,9 +49,10 @@ static long init_record(pmbbo)
switch (pmbbo->out.type) {
case (VME_IO) :
pvmeio = &(pmbbo->out.value.vmeio);
pmbbo->mask = masks[pmbbo->nobt]<<pvmeio->signal;
pmbbo->shft = pvmeio->signal;
pmbbo->mask <<= pmbbo->shft;
status = bo_read(pvmeio->card,pmbbo->mask,&value,BB902);
if(status==0) pmbbo->rval = value>> pvmeio->signal;
if(status==0) pmbbo->rbv = pmbbo->rval = value;
break;
default :
strcpy(message,pmbbo->name);
@@ -73,7 +62,7 @@ static long init_record(pmbbo)
}
return(0);
}
static long write_mbbo(pmbbo)
struct mbboRecord *pmbbo;
{
@@ -83,24 +72,11 @@ static long write_mbbo(pmbbo)
pvmeio = &(pmbbo->out.value.vmeio);
if(pmbbo->sdef) {
unsigned long *pvalues = &(pmbbo->zrvl);
if(pmbbo->val>15) {
if(pmbbo->nsev<MAJOR_ALARM ) {
pmbbo->nsta = SOFT_ALARM;
pmbbo->nsev = MAJOR_ALARM;
}
return(0);
}
value=pvalues[pmbbo->val];
pmbbo->rval = value<<pvmeio->signal;
} else pmbbo->rval = ((unsigned long)(pmbbo->val))<<pvmeio->signal;
status = bo_driver(pvmeio->card,pmbbo->rval,pmbbo->mask,BB902);
if(status==0) {
status = bo_read(pvmeio->card,pmbbo->mask,&value,BB902);
if(status==0) pmbbo->rval = value>> pvmeio->signal;
if(status==0) pmbbo->rbv = value;
else if(pmbbo->nsev<MAJOR_ALARM ) {
pmbbo->nsta = READ_ALARM;
pmbbo->nsev = MAJOR_ALARM;

View File

@@ -60,19 +60,26 @@ static long init_record(pmbbo)
}
return(0);
}
static long write_mbbo(pmbbo)
struct mbboRecord *pmbbo;
{
char message[100];
long status;
/* mbbo.out must be a CONSTANT or a DB_LINK or a CA_LINK*/
switch (pmbbo->out.type) {
case (CONSTANT) :
break;
case (DB_LINK) :
(void)dbPutLink(&pmbbo->out.value.db_link,pmbbo,DBR_ENUM,
status = dbPutLink(&pmbbo->out.value.db_link,pmbbo,DBR_USHORT,
&pmbbo->val,1L);
if(status!=0) {
if(pmbbo->nsev<MAJOR_ALARM) {
pmbbo->nsev = MAJOR_ALARM;
pmbbo->nsta = LINK_ALARM;
}
}
break;
case (CA_LINK) :
break;
@@ -82,7 +89,7 @@ static long write_mbbo(pmbbo)
pmbbo->nsta = SOFT_ALARM;
if(pmbbo->stat!=SOFT_ALARM) {
strcpy(message,pmbbo->name);
strcat(message,": devMbboSoft (write_mbbo) Illegal INP field");
strcat(message,": devMbboSoft (write_mbbo) Illegal OUT field");
errMessage(S_db_badField,message);
}
}

View File

@@ -36,19 +36,7 @@ struct {
init_record,
NULL,
write_mbbo};
static long masks[] = {
0x00000000,
0x00000001, 0x00000003, 0x00000007, 0x0000000f,
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff
};
static long init_record(pmbbo)
struct mbboRecord *pmbbo;
{
@@ -61,9 +49,10 @@ static long init_record(pmbbo)
switch (pmbbo->out.type) {
case (VME_IO) :
pvmeio = &(pmbbo->out.value.vmeio);
pmbbo->mask = masks[pmbbo->nobt]<<pvmeio->signal;
pmbbo->shft = pvmeio->signal;
pmbbo->mask = pmbbo->shft;
status = bo_read(pvmeio->card,pmbbo->mask,&value,XY220);
if(status==0) pmbbo->rval = value>> pvmeio->signal;
if(status==0) pmbbo->rbv = pmbbo->rval = value;
break;
default :
strcpy(message,pmbbo->name);
@@ -83,24 +72,10 @@ static long write_mbbo(pmbbo)
pvmeio = &(pmbbo->out.value.vmeio);
if(pmbbo->sdef) {
unsigned long *pvalues = &(pmbbo->zrvl);
if(pmbbo->val>15) {
if(pmbbo->nsev<MAJOR_ALARM ) {
pmbbo->nsta = SOFT_ALARM;
pmbbo->nsev = MAJOR_ALARM;
}
return(0);
}
value=pvalues[pmbbo->val];
pmbbo->rval = value<<pvmeio->signal;
} else pmbbo->rval = ((unsigned long)(pmbbo->val))<<pvmeio->signal;
status = bo_driver(pvmeio->card,pmbbo->rval,pmbbo->mask,XY220);
if(status==0) {
status = bo_read(pvmeio->card,pmbbo->mask,&value,XY220);
if(status==0) pmbbo->rval = value>> pvmeio->signal;
if(status==0) pmbbo->rbv = value;
else if(pmbbo->nsev<MAJOR_ALARM ) {
pmbbo->nsta = READ_ALARM;
pmbbo->nsev = MAJOR_ALARM;

View File

@@ -170,7 +170,7 @@ static long process(paddr)
return(S_dev_missingSup);
}
/*pact must not be set true until read_ai completes*/
/*pact must not be set true until read_ai is called*/
status=(*pdset->read_ai)(pai); /* read the new value */
pai->pact = TRUE;
/* status is one if an asynchronous record is being processed*/
@@ -280,9 +280,16 @@ static long get_alarm_double(paddr,pad)
static void alarm(pai)
struct aiRecord *pai;
{
float ftemp;
float val=pai->val;
double ftemp;
double val=pai->val;
if(val>0.0 && val<udfDtest){
if (pai->nsev<VALID_ALARM){
pai->nsta = SOFT_ALARM;
pai->nsev = VALID_ALARM;
}
return;
}
/* if difference is not > hysterisis use lalm not val */
ftemp = pai->lalm - pai->val;
if(ftemp<0.0) ftemp = -ftemp;
@@ -333,10 +340,10 @@ static void alarm(pai)
static void convert(pai)
struct aiRecord *pai;
{
float val;
double val;
val = pai->rval;
val = pai->rval + pai->roff;
/* adjust slope and offset */
if(pai->aslo != 0.0) val = val * pai->aslo + pai->aoff;
@@ -406,7 +413,7 @@ static void monitor(pai)
struct aiRecord *pai;
{
unsigned short monitor_mask;
float delta;
double delta;
short stat,sevr,nsta,nsev;
/* get previous stat and sevr and new stat and sevr*/
@@ -420,10 +427,6 @@ static void monitor(pai)
pai->nsta = 0;
pai->nsev = 0;
/* anyone waiting for an event on this record */
if (pai->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */

View File

@@ -125,7 +125,7 @@ struct aodset { /* analog input dset */
#define LINEAR 1
void alarm();
void convert();
int convert();
void monitor();
@@ -139,6 +139,10 @@ static long init_record(pao)
recGblRecordError(S_dev_noDSET,pao,"ao: init_record");
return(S_dev_noDSET);
}
/* get the initial value if dol is a constant*/
if (pao->dol.type == CONSTANT){
pao->val = pao->dol.value.value;
}
/* must have write_ao function defined */
if( (pdset->number < 6) || (pdset->write_ao ==NULL) ) {
recGblRecordError(S_dev_missingSup,pao,"ao: init_record");
@@ -146,10 +150,13 @@ static long init_record(pao)
}
if( pdset->init_record ) {
if((status=(*pdset->init_record)(pao,process))) return(status);
}
/* get the intial value */
if ((pao->dol.type == CONSTANT) && (pao->dol.value.value != udfFloat)){
pao->val = pao->dol.value.value;
if(pao->rval != udfLong) { /* convert */
if (pao->linr == LINEAR){
pao->val = (pao->rval + pao->roff)*pao->eslo + pao->egul;
}else{
pao->val = pao->rval;
}
}
}
return(0);
}
@@ -159,7 +166,7 @@ static long process(paddr)
{
struct aoRecord *pao=(struct aoRecord *)(paddr->precord);
struct aodset *pdset = (struct aodset *)(pao->dset);
long status;
long status=0;
if( (pdset==NULL) || (pdset->write_ao==NULL) ) {
pao->pact=TRUE;
@@ -167,8 +174,11 @@ static long process(paddr)
return(S_dev_missingSup);
}
if(pao->pact == FALSE) convert(pao);
status=(*pdset->write_ao)(pao);
if(pao->pact == FALSE) { /* convert and if success write*/
if(convert(pao)==0) status=(*pdset->write_ao)(pao);
} else {
status=(*pdset->write_ao)(pao);
}
pao->pact = TRUE;
if(status==1) return(0);
@@ -278,6 +288,14 @@ static void alarm(pao)
float ftemp;
float val=pao->val;
if(val>0.0 && val<udfFtest){
if (pao->nsev<VALID_ALARM){
pao->nsta = SOFT_ALARM;
pao->nsev = VALID_ALARM;
}
return;
}
/* if difference is not > hysterisis use lalm not val */
ftemp = pao->lalm - pao->val;
if(ftemp<0.0) ftemp = -ftemp;
@@ -326,12 +344,11 @@ static void alarm(pao)
}
static void convert(pao)
static int convert(pao)
struct aoRecord *pao;
{
float value;
/* fetch the desired output if there is a database link */
if ((pao->dol.type == DB_LINK) && (pao->omsl == CLOSED_LOOP)){
long nRequest;
long options;
@@ -342,18 +359,27 @@ static void convert(pao)
nRequest=1;
save_pact = pao->pact;
pao->pact = TRUE;
status = dbGetLink(&pao->dol.value,DBR_FLOAT,&value,&options,&nRequest);
status = dbGetLink(&pao->dol.value.db_link,pao,DBR_FLOAT,
&value,&options,&nRequest);
pao->pact = save_pact;
if(status) {
if(pao->nsev<VALID_ALARM) {
pao->nsta = LINK_ALARM;
pao->nsev=VALID_ALARM;
}
return;
return(1);
}
if (pao->oif == OUTPUT_INCREMENTAL) value += pao->val;
} else value = pao->val;
if(value>0.0 && value<udfFtest) {
if(pao->nsev<VALID_ALARM) {
pao->nsta = SOFT_ALARM;
pao->nsev = VALID_ALARM;
}
return(1);
}
/* check drive limits */
if(pao->drvh > pao->drvl) {
if (value > pao->drvh) value = pao->drvh;
@@ -361,10 +387,10 @@ static void convert(pao)
}
pao->val = value;
if(pao->oval == udfFloat) pao->oval = value;
if(pao->oval>0.0 && pao->oval<udfFtest) pao->oval = value;
/* now set value equal to desired output value */
/* apply the output rate of change */
if (pao->oroc){
if (pao->oroc<0.0 || pao->oroc>=udfFtest){/*must be defined and >0*/
float diff;
diff = value - pao->oval;
@@ -374,14 +400,17 @@ static void convert(pao)
}
pao->oval = value;
/* convert */
if (pao->linr == LINEAR){
if (pao->eslo == 0.0) pao->rval = 0;
else pao->rval = (value - pao->egul) / pao->eslo;
else {
pao->rval = (value - pao->egul) / pao->eslo;
pao->rval -= pao->roff;
}
}else{
pao->rval = value;
}
return(0);
}
@@ -403,10 +432,6 @@ static void monitor(pao)
pao->nsta = 0;
pao->nsev = 0;
/* anyone waiting for an event on this record */
if (pao->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -426,7 +451,6 @@ static void monitor(pao)
/* update last value monitored */
pao->mlst = pao->val;
}
/* check for archive change */
delta = pao->alst - pao->val;
if(delta<0.0) delta = -delta;
@@ -437,20 +461,22 @@ static void monitor(pao)
pao->alst = pao->val;
}
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(pao,&pao->val,monitor_mask);
}
if(pao->oraw != pao->rval) {
monitor_mask |= DBE_VALUE;
db_post_events(pao,&pao->rval,monitor_mask);
if(pao->oval!=pao->val) monitor_mask |= (DBE_VALUE|DBE_LOG);
if(monitor_mask) {
db_post_events(pao,&pao->oval,monitor_mask);
pao->oraw = pao->rval;
}
if(pao->orbv != pao->rbv) {
monitor_mask |= DBE_VALUE;
db_post_events(pao,&pao->rbv,monitor_mask);
pao->orbv = pao->rbv;
if(pao->oraw != pao->rval) {
db_post_events(pao,&pao->rval,monitor_mask|DBE_VALUE);
pao->oraw = pao->rval;
}
if(pao->orbv != pao->rbv) {
db_post_events(pao,&pao->rbv,monitor_mask|DBE_VALUE);
pao->orbv = pao->rbv;
}
}
return;
}

View File

@@ -102,7 +102,9 @@ struct bidset { /* binary input dset */
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;/*(-1,0,1)=>(failure,success,don't Continue*/
DEVSUPFUN read_bi;/*(0,1,2)=> success and */
/*(convert,don't continue, don't convert)*/
/* if convert then raw value stored in rval */
};
void alarm();
void monitor();
@@ -143,10 +145,13 @@ static long process(paddr)
status=(*pdset->read_bi)(pbi); /* read the new value */
pbi->pact = TRUE;
if(status==0) { /* convert rval to val */
if(pbi->rval==0) pbi->val =0;
else pbi->val = 1;
}
/* status is one if an asynchronous record is being processed*/
if(status==1) return(1);
else if(status==1) return(0);
else if(status==2) status=0;
/* check for alarms */
alarm(pbi);
/* check event list */
@@ -217,6 +222,14 @@ static void alarm(pbi)
unsigned short val = pbi->val;
if(val==udfUshort){
if (pbi->nsev<VALID_ALARM){
pbi->nsta = SOFT_ALARM;
pbi->nsev = VALID_ALARM;
}
return;
}
if(val>1)return;
/* check for state alarm */
if (val == 0){
@@ -232,6 +245,7 @@ static void alarm(pbi)
}
/* check for cos alarm */
if(pbi->lalm==udfUshort) pbi->lalm = val;
if(val == pbi->lalm) return;
if (pbi->nsev<pbi->cosv) {
pbi->nsta = COS_ALARM;
@@ -258,10 +272,6 @@ static void monitor(pbi)
pbi->nsta = 0;
pbi->nsev = 0;
/* anyone waiting for an event on this record */
if (pbi->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */

View File

@@ -121,6 +121,7 @@ struct bodset { /* binary output dset */
/* control block for callback*/
struct callback {
void (*callback)();
int priority;
struct dbAddr dbAddr;
WDOG_ID wd_id;
};
@@ -159,21 +160,27 @@ static long init_record(pbo)
recGblRecordError(S_dev_missingSup,pbo,"bo: init_record");
return(S_dev_missingSup);
}
/* get the intial value */
if (pbo->dol.type == CONSTANT & pbo->dol.value.value!=udfFloat){
if (pbo->dol.value.value == 1) pbo->val = 1;
else pbo->val = 0;
}
if( pdset->init_record ) {
if((status=(*pdset->init_record)(pbo,process))) return(status);
/* get the initial value */
if (pbo->dol.type == CONSTANT
&& (pbo->dol.value.value<0.0 || pbo->dol.value.value>=udfFtest)){
if (pbo->dol.value.value == 0) pbo->val = 0;
else pbo->val = 1;
}
pcallback = (struct callback *)(calloc(1,sizeof(struct callback)));
pbo->dpvt = (caddr_t)pcallback;
pcallback->callback = myCallback;
pcallback->priority = priorityMedium;
if(dbNameToAddr(pbo->name,&(pcallback->dbAddr))) {
logMsg("dbNameToAddr failed in init_record for recBo\n");
exit(1);
}
if( pdset->init_record ) {
if((status=(*pdset->init_record)(pbo,process))) return(status);
if(pbo->rval!=udfUlong) { /* convert*/
if(pbo->rval==0) pbo->val = 0;
else pbo->val = 1;
}
}
return(0);
}
@@ -190,36 +197,41 @@ static long process(paddr)
recGblRecordError(S_dev_missingSup,pbo,"write_bo");
return(S_dev_missingSup);
}
if (!pbo->pact) {
if((pbo->dol.type == DB_LINK) && (pbo->omsl == CLOSED_LOOP)){
long options=0;
long nRequest=1;
unsigned short val;
/* fetch the desired output if there is a database link */
if ( !(pbo->pact) && (pbo->dol.type == DB_LINK) && (pbo->omsl == CLOSED_LOOP)){
long options=0;
long nRequest=1;
short savepact=pbo->pact;
unsigned short val;
pbo->pact = TRUE;
status = dbGetLink(&pbo->dol.value.db_link,pbo,
DBR_USHORT,&(pbo->val),&options,&nRequest);
if(status) {
if(pbo->nsev < VALID_ALARM) {
pbo->nsev = VALID_ALARM;
pbo->nsta = LINK_ALARM;
pbo->pact = TRUE;
status = dbGetLink(&pbo->dol.value.db_link,pbo,
DBR_USHORT,&val,&options,&nRequest);
pbo->pact = FALSE;
if(status==0){
pbo->val = val;
}else {
if(pbo->nsev < VALID_ALARM) {
pbo->nsev = VALID_ALARM;
pbo->nsta = LINK_ALARM;
}
}
}
else if(val==0) pbo->val = 0;
else pbo->val = 1;
pbo->pact = savepact;
}
status=(*pdset->write_bo)(pbo); /* write the new value */
if(pbo->mask != udfUlong) {
if(pbo->val==0) pbo->rval = 0;
else pbo->rval = pbo->mask;
}
}
if(pbo->val==udfEnum) {
if(pbo->nsev < VALID_ALARM) {
pbo->nsev = VALID_ALARM;
pbo->nsta = SOFT_ALARM;
}
status = 0;
} else status=(*pdset->write_bo)(pbo); /* write the new value */
pbo->pact = TRUE;
/* status is one if an asynchronous record is being processed*/
if(status==1) return(0);
wait_time = (int)(pbo->high) * vxTicksPerSecond; /* seconds to ticks */
wait_time = (int)(pbo->high) * vxTicksPerSecond; /* seconds to ticks */
if(pbo->val==1 && wait_time>0) {
struct callback *pcallback;
@@ -227,8 +239,6 @@ static long process(paddr)
if(pcallback->wd_id==NULL) pcallback->wd_id = wdCreate();
wdStart(pcallback->wd_id,wait_time,callbackRequest,pcallback);
}
/* check for alarms */
alarm(pbo);
/* check event list */
@@ -312,6 +322,7 @@ static void alarm(pbo)
}
/* check for cos alarm */
if(pbo->lalm==udfUshort) pbo->lalm = val;
if(val == pbo->lalm) return;
if (pbo->nsev<pbo->cosv) {
pbo->nsta = COS_ALARM;
@@ -338,10 +349,6 @@ static void monitor(pbo)
pbo->nsta = 0;
pbo->nsev = 0;
/* anyone waiting for an event on this record */
if (pbo->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */

View File

@@ -54,13 +54,14 @@
* .17 04-06-90 lrd change conditional to check for 0 and non-zero
* instead of 0 and 1 (more 'C' like)
* .18 10-10-90 mrk Made changes for new record support
* Note that all calc specific details moved
* to libCalc
*/
#include <vxWorks.h>
#include <types.h>
#include <stdioLib.h>
#include <lstLib.h>
#include <math.h>
#include <alarm.h>
#include <dbAccess.h>
@@ -71,7 +72,6 @@
#include <recSup.h>
#include <special.h>
#include <calcRecord.h>
#include <post.h>
/* Create RSET - Record Support Entry Table*/
#define report NULL
@@ -114,23 +114,26 @@ struct rset calcRSET={
void alarm();
void monitor();
int do_calc();
long calcPerform();
long postfix();
void fetch_values();
int fetch_values();
#define ARG_MAX 12
static long init_record(pcalc)
struct calcRecord *pcalc;
{
long status;
struct link *plink;
int i;
double *pvalue;
short error_number;
char rpbuf[80];
if(pcalc->inpa.type==CONSTANT) pcalc->a = pcalc->inpa.value.value;
if(pcalc->inpb.type==CONSTANT) pcalc->b = pcalc->inpb.value.value;
if(pcalc->inpc.type==CONSTANT) pcalc->c = pcalc->inpc.value.value;
if(pcalc->inpd.type==CONSTANT) pcalc->d = pcalc->inpd.value.value;
if(pcalc->inpe.type==CONSTANT) pcalc->e = pcalc->inpe.value.value;
if(pcalc->inpf.type==CONSTANT) pcalc->f = pcalc->inpf.value.value;
plink = &pcalc->inpa;
pvalue = &pcalc->a;
for(i=0; i<ARG_MAX; i++, plink++, pvalue++) {
if(plink->type==CONSTANT) *pvalue = plink->value.value;
}
status=postfix(pcalc->calc,rpbuf,&error_number);
if(status) return(status);
bcopy(rpbuf,pcalc->rpcl,sizeof(pcalc->rpcl));
@@ -143,11 +146,12 @@ static long process(paddr)
struct calcRecord *pcalc=(struct calcRecord *)(paddr->precord);
pcalc->pact = TRUE;
fetch_values(pcalc);
if(do_calc(pcalc)) {
if(pcalc->nsev<VALID_ALARM) {
pcalc->nsta = CALC_ALARM;
pcalc->nsev = VALID_ALARM;
if(fetch_values(pcalc)==0) {
if(calcPerform(&pcalc->a,&pcalc->val,pcalc->rpcl)) {
if(pcalc->nsev<VALID_ALARM) {
pcalc->nsta = CALC_ALARM;
pcalc->nsev = VALID_ALARM;
}
}
}
/* check for alarms */
@@ -176,6 +180,7 @@ static long special(paddr,after)
status=postfix(pcalc->calc,rpbuf,&error_number);
if(status) return(status);
bcopy(rpbuf,pcalc->rpcl,sizeof(pcalc->rpcl));
db_post_events(pcalc,pcalc->calc,DBE_VALUE);
return(0);
default:
recGblDbaddrError(S_db_badChoice,paddr,"calc: special");
@@ -187,9 +192,9 @@ static long get_value(pcalc,pvdes)
struct calcRecord *pcalc;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_FLOAT;
pvdes->field_type = DBF_DOUBLE;
pvdes->no_elements=1;
(float *)(pvdes->pvalue) = &pcalc->val;
(double *)(pvdes->pvalue) = &pcalc->val;
return(0);
}
@@ -251,9 +256,16 @@ static long get_alarm_double(paddr,pad)
static void alarm(pcalc)
struct calcRecord *pcalc;
{
float ftemp;
float val=pcalc->val;
double ftemp;
double val=pcalc->val;
if(val>0.0 && val<udfDtest) {
if(pcalc->nsev<VALID_ALARM) {
pcalc->nsev = VALID_ALARM;
pcalc->nsta = SOFT_ALARM;
}
return;
}
/* if difference is not > hysterisis use lalm not val */
ftemp = pcalc->lalm - pcalc->val;
if(ftemp<0.0) ftemp = -ftemp;
@@ -305,10 +317,10 @@ static void monitor(pcalc)
struct calcRecord *pcalc;
{
unsigned short monitor_mask;
float delta;
double delta;
short stat,sevr,nsta,nsev;
float *pnew;
float *pprev;
double *pnew;
double *pprev;
int i;
/* get previous stat and sevr and new stat and sevr*/
@@ -322,10 +334,6 @@ static void monitor(pcalc)
pcalc->nsta = 0;
pcalc->nsev = 0;
/* anyone waiting for an event on this record */
if (pcalc->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -358,367 +366,47 @@ static void monitor(pcalc)
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(pcalc,&pcalc->val,monitor_mask);
}
/* check all input fields for changes*/
for(i=0, pnew=&pcalc->a, pprev=&pcalc->la; i<6; i++, pnew++, pprev++) {
if(*pnew != *pprev) {
db_post_events(pcalc,pnew,monitor_mask|DBE_VALUE);
*pprev = *pnew;
/* check all input fields for changes*/
for(i=0, pnew=&pcalc->a, pprev=&pcalc->la; i<ARG_MAX; i++, pnew++, pprev++) {
if(*pnew != *pprev) {
db_post_events(pcalc,pnew,monitor_mask|DBE_VALUE);
*pprev = *pnew;
}
}
}
}
return;
}
static void fetch_values(pcalc)
static int fetch_values(pcalc)
struct calcRecord *pcalc;
{
struct link *plink; /* structure of the link field */
float *pvalue;
double *pvalue;
long options,nRequest;
int i;
long status;
for(i=0, plink=&pcalc->inpa, pvalue=&pcalc->a; i<6; i++, plink++, pvalue++) {
for(i=0, plink=&pcalc->inpa, pvalue=&pcalc->a; i<ARG_MAX; i++, plink++, pvalue++) {
if(plink->type!=DB_LINK) continue;
options=0;
nRequest=1;
(void)dbGetLink(&plink->value.db_link,pcalc,DBR_FLOAT,
status = dbGetLink(&plink->value.db_link,pcalc,DBR_DOUBLE,
pvalue,&options,&nRequest);
}
return;
}
/* the floating point math routines need to be declared as doubles */
static double random(); /* random number generator */
double sqrt(),log(),log10();
double acos(),asin(),atan();
double cos(),sin(),tan();
double cosh(),sinh(),tanh();
/*
* DO_CALC
*
* execute the calculation
*/
#define NOT_SET 0
#define TRUE_COND 1
#define FALSE_COND 2
static int do_calc(pcalc)
struct calcRecord *pcalc; /* pointer to calculation record */
{
char *post; /* postfix expression */
double *pstacktop; /* stack of values */
double stack[80];
int temp;
short i;
double *top;
int itop; /* integer top value */
int inexttop; /* ineteger next to top value */
short cond_flag; /* conditional else flag */
/* initialize flag */
cond_flag = NOT_SET;
pstacktop = &stack[0];
/* set post to postfix expression in calc structure */
post = &pcalc->rpcl[0];
top = pstacktop;
/* polish calculator loop */
while (*post != END_STACK){
switch (*post){
case FETCH_A:
++pstacktop;
*pstacktop = pcalc->a;
break;
case FETCH_B:
++pstacktop;
*pstacktop = pcalc->b;
break;
case FETCH_C:
++pstacktop;
*pstacktop = pcalc->c;
break;
case FETCH_D:
++pstacktop;
*pstacktop = pcalc->d;
break;
case FETCH_E:
++pstacktop;
*pstacktop = pcalc->e;
break;
case FETCH_F:
++pstacktop;
*pstacktop = pcalc->f;
break;
case ADD:
--pstacktop;
*pstacktop = *pstacktop + *(pstacktop+1);
break;
case SUB:
--pstacktop;
*pstacktop = *pstacktop - *(pstacktop+1);
break;
case MULT:
--pstacktop;
*pstacktop = *pstacktop * *(pstacktop+1);
break;
case DIV:
--pstacktop;
if (*(pstacktop+1) == 0) /* can't divide by zero */
return(-1);
*pstacktop = *pstacktop / *(pstacktop+1);
break;
case COND_ELSE:
/* first conditional set cond_flag */
/* true */
if ((*pstacktop != 0.0) && (cond_flag == NOT_SET)){
cond_flag = TRUE_COND;
--pstacktop; /* remove condition */
/* false */
}else if ((*pstacktop==0.0) && (cond_flag==NOT_SET)){
cond_flag = FALSE_COND;
--pstacktop; /* remove condition */
/* check for else condition */
i = 1;
while (*(post+i) != COND_ELSE){
/* no else value */
if (*(post+i) == END_STACK){
/* skip to end of expression */
while (*(post+1) != END_STACK)
++post;
/* use last value as result */
++pstacktop;
*pstacktop = pcalc->val;
}
i++;
}
}else if (cond_flag == TRUE_COND){
/* skip expression - result is on stack */
while ((*(post+1) != COND_ELSE)
&& (*(post+1) != END_STACK))
++post;
}else if (cond_flag == FALSE_COND){
/* remove true answer from stack top */
--pstacktop;
if(status!=0) {
if(pcalc->nsev<VALID_ALARM) {
pcalc->nsev=VALID_ALARM;
pcalc->nsta=LINK_ALARM;
}
break;
case ABS_VAL:
if (*pstacktop < 0) *pstacktop = -*pstacktop;
break;
case UNARY_NEG:
*pstacktop = -1* (*pstacktop);
break;
case SQU_RT:
if (*pstacktop < 0) return(-1); /* undefined */
*pstacktop = sqrt(*pstacktop);
break;
case LOG_10:
*pstacktop = log10(*pstacktop);
break;
case LOG_E:
*pstacktop = log(*pstacktop);
break;
case RANDOM:
++pstacktop;
*pstacktop = random();
break;
case EXPON:
--pstacktop;
if (*pstacktop < 0){
temp = (int) *(pstacktop+1);
/* is exponent an integer */
if ((*(pstacktop+1) - (double)temp) != 0) return (-1);
*pstacktop = exp(*(pstacktop+1) * log(-*pstacktop));
/* is value negative */
if ((temp % 2) > 0) *pstacktop = -*pstacktop;
}else{
*pstacktop = exp(*(pstacktop+1) * log(*pstacktop));
return(-1);
}
if(*pvalue>0.0 && *pvalue<udfDtest) {
if(pcalc->nsev<VALID_ALARM) {
pcalc->nsev=VALID_ALARM;
pcalc->nsta=SOFT_ALARM;
}
break;
case MODULO:
--pstacktop;
itop = (int)*pstacktop;
inexttop = (int)*(pstacktop+1);
if (inexttop == 0)
return(-1);
i = itop % inexttop;
*pstacktop = i;
break;
case REL_OR:
--pstacktop;
*pstacktop = (*pstacktop || *(pstacktop+1));
break;
case REL_AND:
--pstacktop;
*pstacktop = (*pstacktop && *(pstacktop+1));
break;
case BIT_OR:
/* force double values into integers and or them */
itop = (int)*pstacktop;
inexttop = (int)*(pstacktop-1);
--pstacktop;
*pstacktop = (inexttop | itop);
break;
case BIT_AND:
/* force double values into integers and and them */
itop = (int)*pstacktop;
inexttop = (int)*(pstacktop-1);
--pstacktop;
*pstacktop = (inexttop & itop);
break;
case BIT_EXCL_OR:
/*force double values to integers to exclusive or them*/
itop = (int)*pstacktop;
inexttop = (int)*(pstacktop-1);
--pstacktop;
*pstacktop = (inexttop ^ itop);
break;
case GR_OR_EQ:
--pstacktop;
*pstacktop = *pstacktop >= *(pstacktop+1);
break;
case GR_THAN:
--pstacktop;
*pstacktop = *pstacktop > *(pstacktop+1);
break;
case LESS_OR_EQ:
--pstacktop;
*pstacktop = *pstacktop <= *(pstacktop+1);
break;
case LESS_THAN:
--pstacktop;
*pstacktop = *pstacktop < *(pstacktop+1);
break;
case NOT_EQ:
--pstacktop;
*pstacktop = *pstacktop != *(pstacktop+1);
break;
case EQUAL:
--pstacktop;
*pstacktop = (*pstacktop == *(pstacktop+1));
break;
case RIGHT_SHIFT:
itop = (int)*pstacktop;
inexttop = (int)*(pstacktop-1);
--pstacktop;
*pstacktop = (inexttop >> itop);
break;
case LEFT_SHIFT:
itop = (int)*pstacktop;
inexttop = (int)*(pstacktop-1);
--pstacktop;
*pstacktop = (inexttop << itop);
break;
case ACOS:
*pstacktop = acos(*pstacktop);
break;
case ASIN:
*pstacktop = asin(*pstacktop);
break;
case ATAN:
*pstacktop = atan(*pstacktop);
break;
case COS:
*pstacktop = cos(*pstacktop);
break;
case SIN:
*pstacktop = sin(*pstacktop);
break;
case TAN:
*pstacktop = tan(*pstacktop);
break;
case COSH:
*pstacktop = cosh(*pstacktop);
break;
case SINH:
*pstacktop = sinh(*pstacktop);
break;
case TANH:
*pstacktop = tanh(*pstacktop);
break;
default:
printf("%d bad expression element\n",*post);
break;
return(-1);
}
/* move ahead in postfix expression */
++post;
}
/* if everything is peachy,the stack should end at its first position */
if (++top == pstacktop)
pcalc->val = *pstacktop;
else {
if(pcalc->nsev < MAJOR_ALARM) {
pcalc->nsev = MAJOR_ALARM;
pcalc->nsta = CALC_ALARM;
}
}
return(0);
}
/*
* RANDOM
*
* generates a random number between 0 and 1 using the
* seed = (multy * seed) + addy Random Number Generator by Knuth
* SemiNumerical Algorithms
* Chapter 1
* randy = 1.0 / (seed & 0xff) To normalize the number between 0 - 1
*/
static unsigned short seed = 0xa3bf;
static unsigned short multy = 191 * 8 + 5; /* 191 % 8 == 5 */
static unsigned short addy = 0x3141;
static double random()
{
double randy;
/* random number */
seed = (seed * multy) + addy;
randy = 1.0 / (seed & 0xff);
/* between 0 - 1 */
return(randy);
}

View File

@@ -104,16 +104,17 @@ struct rset compressRSET={
get_control_double,
get_alarm_double };
#define NTO1LOW 0
#define NTO1HIGH 1
#define NTO1AVG 2
#define compressNTO1LOW 0
#define compressNTO1HIGH 1
#define compressNTO1AVG 2
#define AVERAGE 3
#define CIRBUF 4
void alarm();
void monitor();
void put_value();
int compress_array();
int compress_value();
int compress_scalar();
int array_average();
static long init_record(pcompress)
struct compressRecord *pcompress;
@@ -121,16 +122,16 @@ static long init_record(pcompress)
/* This routine may get called twice. Once by cvt_dbaddr. Once by iocInit*/
if(pcompress->bptr==NULL) {
pcompress->bptr = (float *)calloc(pcompress->nsam,sizeof(float));
pcompress->bptr = (double *)calloc(pcompress->nsam,sizeof(double));
/* allocate memory for the summing buffer for conversions requiring it */
if (pcompress->alg == AVERAGE){
pcompress->sptr = (float *)calloc(pcompress->nsam,sizeof(float));
pcompress->sptr = (double *)calloc(pcompress->nsam,sizeof(double));
}
}
if(pcompress->wptr==NULL && pcompress->inp.type==DB_LINK) {
struct dbAddr *pdbAddr = (struct dbAddr *)(pcompress->inp.value.db_link.pdbAddr);
pcompress->wptr = (float *)calloc(pdbAddr->no_elements,sizeof(float));
pcompress->wptr = (double *)calloc(pdbAddr->no_elements,sizeof(double));
}
return(0);
}
@@ -159,7 +160,7 @@ static long process(paddr)
long no_elements=pdbAddr->no_elements;
int alg=pcompress->alg;
(void)dbGetLink(&pcompress->inp.value.db_link,pcompress,DBR_FLOAT,pcompress->wptr,
(void)dbGetLink(&pcompress->inp.value.db_link,pcompress,DBR_DOUBLE,pcompress->wptr,
&options,&no_elements);
if(alg==AVERAGE) {
status = array_average(pcompress,pcompress->wptr,no_elements);
@@ -169,7 +170,7 @@ static long process(paddr)
} else if(pdbAddr->no_elements>1) {
status = compress_array(pcompress,pcompress->wptr,no_elements);
}else if(no_elements==1){
status = compress_value(pcompress,pcompress->wptr);
status = compress_scalar(pcompress,pcompress->wptr);
}else status=1;
}
@@ -211,9 +212,9 @@ static long get_value(pcompress,pvdes)
struct compressRecord *pcompress;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_FLOAT;
pvdes->field_type = DBF_DOUBLE;
pvdes->no_elements=pcompress->nuse;
(float *)(pvdes->pvalue) = pcompress->bptr;
(double *)(pvdes->pvalue) = pcompress->bptr;
return(0);
}
@@ -227,9 +228,9 @@ static long cvt_dbaddr(paddr)
paddr->pfield = (caddr_t)(pcompress->bptr);
paddr->no_elements = pcompress->nsam;
paddr->field_type = DBF_FLOAT;
paddr->field_size = sizeof(float);
paddr->dbr_field_type = DBF_FLOAT;
paddr->field_type = DBF_DOUBLE;
paddr->field_size = sizeof(double);
paddr->dbr_field_type = DBF_DOUBLE;
return(0);
}
@@ -318,10 +319,6 @@ static void monitor(pcompress)
pcompress->nsta = 0;
pcompress->nsev = 0;
/* anyone waiting for an event on this record */
if(pcompress->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -332,21 +329,21 @@ static void monitor(pcompress)
db_post_events(pcompress,&pcompress->stat,DBE_VALUE);
db_post_events(pcompress,&pcompress->sevr,DBE_VALUE);
}
monitor_mask |= DBE_LOG|DBE_VALUE;
monitor_mask |= (DBE_LOG|DBE_VALUE);
if(monitor_mask) db_post_events(pcompress,pcompress->bptr,monitor_mask);
return;
}
static void put_value(pcompress,psource,n)
struct compressRecord *pcompress;
float *psource;
double *psource;
long n;
{
/* treat bptr as pointer to a circular buffer*/
float *pdest;
short offset=pcompress->off;
short nuse=pcompress->nuse;
short nsam=pcompress->nsam;
double *pdest;
long offset=pcompress->off;
long nuse=pcompress->nuse;
long nsam=pcompress->nsam;
long i;
pdest = pcompress->bptr + offset;
@@ -366,15 +363,15 @@ static void put_value(pcompress,psource,n)
static int compress_array(pcompress,psource,no_elements)
struct compressRecord *pcompress;
float *psource;
double *psource;
long no_elements;
{
long i,j;
int nnew;
short nsam=pcompress->nsam;
float *pdest;
float value;
short n;
long nnew;
long nsam=pcompress->nsam;
double *pdest;
double value;
long n;
/* skip out of limit data */
if (pcompress->ilil < pcompress->ihil){
@@ -394,7 +391,7 @@ long no_elements;
/* compress according to specified algorithm */
switch (pcompress->alg){
case (NTO1LOW):
case (compressNTO1LOW):
/* compress N to 1 keeping the lowest value */
for (i = 0; i < nnew; i++){
value = *psource++;
@@ -404,7 +401,7 @@ long no_elements;
put_value(pcompress,&value,1);
}
break;
case (NTO1HIGH):
case (compressNTO1HIGH):
/* compress N to 1 keeping the highest value */
for (i = 0; i < nnew; i++){
value = *psource++;
@@ -414,7 +411,7 @@ long no_elements;
put_value(pcompress,&value,1);
}
break;
case (NTO1AVG):
case (compressNTO1AVG):
/* compress N to 1 keeping the average value */
for (i = 0; i < nnew; i++){
value = 0;
@@ -430,24 +427,24 @@ long no_elements;
static int array_average(pcompress,psource,no_elements)
struct compressRecord *pcompress;
float *psource;
double *psource;
long no_elements;
{
long i;
int nnow;
short nsam=pcompress->nsam;
float *psum;
float multiplier;
short inx=pcompress->inx;
long nnow;
long nsam=pcompress->nsam;
double *psum;
double multiplier;
long inx=pcompress->inx;
struct dbAddr *pdbAddr = (struct dbAddr *)(pcompress->inp.value.db_link.pdbAddr);
long ninp=pdbAddr->no_elements;
short nuse,n;
long nuse,n;
nuse = nsam;
if(nuse>ninp) nuse = ninp;
nnow=nuse;
if(nnow>no_elements) nnow=no_elements;
psum = (float *)pcompress->sptr;
psum = (double *)pcompress->sptr;
/* add in the new waveform */
if (inx == 0){
@@ -465,8 +462,8 @@ long no_elements;
n = pcompress->n;
if(inx<n) return(1);
if(n>1) {
psum = (float *)pcompress->sptr;
multiplier = 1.0/((float)n);
psum = (double *)pcompress->sptr;
multiplier = 1.0/((double)n);
for (i = 0; i < nuse; i++, psum++)
*psum = *psum * multiplier;
}
@@ -474,25 +471,25 @@ long no_elements;
return(0);
}
static int compress_value(pcompress,psource)
static int compress_scalar(pcompress,psource)
struct compressRecord *pcompress;
float *psource;
double *psource;
{
float value = *psource;
float *pdest=&pcompress->cvb;
short inx = pcompress->inx;
double value = *psource;
double *pdest=&pcompress->cvb;
long inx = pcompress->inx;
/* compress according to specified algorithm */
switch (pcompress->alg){
case (NTO1LOW):
case (compressNTO1LOW):
if ((value < *pdest) || (inx == 0))
*pdest = value;
break;
case (NTO1HIGH):
case (compressNTO1HIGH):
if ((value > *pdest) || (inx == 0))
*pdest = value;
break;
case (NTO1AVG):
case (compressNTO1AVG):
if (inx == 0)
*pdest = value;
else {

View File

@@ -89,19 +89,58 @@ struct rset fanoutRSET={
get_graphic_double,
get_control_double,
get_alarm_double };
#define SELECT_ALL 0
#define SELECTED 1
static long process(paddr)
struct dbAddr *paddr;
{
struct fanoutRecord *pfanout=(struct fanoutRecord *)(paddr->precord);
short stat,sevr,nsta,nsev;
pfanout->pact = TRUE;
pfanout->pact = TRUE;
if(pfanout->selm==SELECT_ALL) {
if (pfanout->lnk1.type==DB_LINK) dbScanPassive(pfanout->lnk1.value.db_link.pdbAddr);
if (pfanout->lnk2.type==DB_LINK) dbScanPassive(pfanout->lnk2.value.db_link.pdbAddr);
if (pfanout->lnk3.type==DB_LINK) dbScanPassive(pfanout->lnk3.value.db_link.pdbAddr);
if (pfanout->lnk4.type==DB_LINK) dbScanPassive(pfanout->lnk4.value.db_link.pdbAddr);
if (pfanout->lnk5.type==DB_LINK) dbScanPassive(pfanout->lnk5.value.db_link.pdbAddr);
if (pfanout->lnk6.type==DB_LINK) dbScanPassive(pfanout->lnk6.value.db_link.pdbAddr);
pfanout->pact=FALSE;
return(0);
} else if(pfanout->selm==SELECTED) {
if(pfanout->seln<1 || pfanout->seln>6) {
if(pfanout->nsev<MAJOR_ALARM) {
pfanout->nsev = MAJOR_ALARM;
pfanout->nsta = SOFT_ALARM;
}
} else {
struct link *plink;
plink=&(pfanout->lnk1);
plink += (pfanout->seln-1);
dbScanPassive(plink->value.db_link.pdbAddr);
}
} else {
if(pfanout->nsev<MAJOR_ALARM) {
pfanout->nsev = MAJOR_ALARM;
pfanout->nsta = SOFT_ALARM;
}
}
/* check monitors*/
/* get previous stat and sevr and new stat and sevr*/
stat=pfanout->stat;
sevr=pfanout->sevr;
nsta=pfanout->nsta;
nsev=pfanout->nsev;
/*set current stat and sevr*/
pfanout->stat = nsta;
pfanout->sevr = nsev;
pfanout->nsta = 0;
pfanout->nsev = 0;
if((stat!=nsta || sevr!=nsev)){
db_post_events(pfanout,&pfanout->stat,DBE_VALUE);
db_post_events(pfanout,&pfanout->sevr,DBE_VALUE);
}
pfanout->pact=FALSE;
return(0);
}

View File

@@ -135,6 +135,7 @@ static long init_record(pmbbi)
{
struct mbbidset *pdset;
long status;
int i;
init_common(pmbbi);
if(!(pdset = (struct mbbidset *)(pmbbi->dset))) {
@@ -146,6 +147,12 @@ static long init_record(pmbbi)
recGblRecordError(S_dev_missingSup,pmbbi,"mbbi: init_record");
return(S_dev_missingSup);
}
/* initialize mask*/
pmbbi->mask = 0;
for (i=0; i<pmbbi->nobt; i++) {
pmbbi->mask <<= 1; /* shift left 1 bit*/
pmbbi->mask |= 1; /* set low order bit*/
}
if( pdset->init_record ) {
if((status=(*pdset->init_record)(pmbbi,process))) return(status);
}
@@ -158,7 +165,6 @@ static long process(paddr)
struct mbbiRecord *pmbbi=(struct mbbiRecord *)(paddr->precord);
struct mbbidset *pdset = (struct mbbidset *)(pmbbi->dset);
long status;
unsigned short val;
if( (pdset==NULL) || (pdset->read_mbbi==NULL) ) {
pmbbi->pact=TRUE;
@@ -168,29 +174,31 @@ static long process(paddr)
status=(*pdset->read_mbbi)(pmbbi); /* read the new value */
pmbbi->pact = TRUE;
if(status==1) return(0);
if(status==0) { /* convert the value */
unsigned long *pstate_values;
short i;
unsigned long rval = pmbbi->rval;
if(pmbbi->shft>0) rval >>= pmbbi->shft;
if (pmbbi->sdef){
pstate_values = &(pmbbi->zrvl);
val = udfUshort; /* initalize to unknown state*/
if(rval!=udfUlong)for (i = 0; i < 16; i++){
if (*pstate_values == rval){
val = i;
break;
}
pstate_values++;
pmbbi->val = udfUshort;/* initalize to unknown state*/
if(rval!=udfUlong) {
for (i = 0; i < 16; i++){
if (*pstate_values == rval){
pmbbi->val = i;
break;
}
pstate_values++;
}
}
}else{
/* the raw value is the desired value */
*((unsigned short *)(&val)) = (unsigned short)(pmbbi->rval);
pmbbi->val = (unsigned short)rval;
}
pmbbi->val = val;
}
if(status == 2) status = 0;
else if(status==1) return(0);
else if(status == 2) status = 0;
/* check for alarms */
alarm(pmbbi);
@@ -292,12 +300,12 @@ static void alarm(pmbbi)
struct mbbiRecord *pmbbi;
{
unsigned short *severities;
short val=pmbbi->val;
unsigned short val=pmbbi->val;
/* check for state alarm */
/* unknown state */
if ((val < 0) || (val > 15)){
if (val > 15){
if (pmbbi->nsev<pmbbi->unsv){
pmbbi->nsta = STATE_ALARM;
pmbbi->nsev = pmbbi->unsv;
@@ -312,6 +320,7 @@ static void alarm(pmbbi)
}
/* check for cos alarm */
if(pmbbi->lalm==udfUshort) pmbbi->lalm = val;
if(val == pmbbi->lalm) return;
if (pmbbi->nsev<pmbbi->cosv){
pmbbi->nsta = COS_ALARM;
@@ -339,10 +348,6 @@ static void monitor(pmbbi)
pmbbi->nsta = 0;
pmbbi->nsev = 0;
/* anyone waiting for an event on this record */
if (pmbbi->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -365,7 +370,7 @@ static void monitor(pmbbi)
db_post_events(pmbbi,&pmbbi->val,monitor_mask);
}
if(pmbbi->oraw!=pmbbi->rval) {
db_post_events(pmbbi,&pmbbi->rval,monitor_mask);
db_post_events(pmbbi,&pmbbi->rval,monitor_mask|DBE_VALUE);
pmbbi->oraw = pmbbi->rval;
}
return;

View File

@@ -111,7 +111,7 @@ struct mbbodset { /* multi bit binary input dset */
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_mbbo;/*(-1,0,1)=>(failure,success,don't Continue*/
DEVSUPFUN write_mbbo;/*(0,1)=>(success,don't Continue*/
};
@@ -136,13 +136,13 @@ static void init_common(pmbbo)
}
return;
}
static long init_record(pmbbo)
struct mbboRecord *pmbbo;
{
struct mbbodset *pdset;
long status;
unsigned short rbv;
int i;
init_common(pmbbo);
@@ -155,32 +155,42 @@ static long init_record(pmbbo)
recGblRecordError(S_dev_missingSup,pmbbo,"mbbo: init_record");
return(S_dev_missingSup);
}
if( pdset->init_record ) {
if((status=(*pdset->init_record)(pmbbo,process))) return(status);
if (pmbbo->sdef){
unsigned long *pstate_values;
short i;
unsigned long rval = pmbbo->rval;
pstate_values = &(pmbbo->zrvl);
rbv = udfUshort; /* initalize to unknown state*/
if(rval!=udfUlong) for (i = 0; i < 16; i++){
if (*pstate_values == rval){
rbv = i;
break;
}
pstate_values++;
}
}else{
/* the raw is the desired rbv */
rbv = (unsigned short)(pmbbo->rval);
}
pmbbo->rbv = rbv;
pmbbo->val = rbv;
}
if ((pmbbo->dol.type == CONSTANT) && (pmbbo->dol.value.value != udfFloat)){
if ((pmbbo->dol.type == CONSTANT)
&& (pmbbo->dol.value.value<0.0 || pmbbo->dol.value.value>=udfFtest)){
pmbbo->val = pmbbo->dol.value.value;
}
/* initialize mask*/
pmbbo->mask = 0;
for (i=0; i<pmbbo->nobt; i++) {
pmbbo->mask <<= 1; /* shift left 1 bit*/
pmbbo->mask |= 1; /* set low order bit*/
}
if( pdset->init_record ) {
unsigned long rval;
if((status=(*pdset->init_record)(pmbbo,process))) return(status);
rval = pmbbo->rval;
if(pmbbo->shft>0 && rval!=udfUlong) rval >>= pmbbo->shft;
if (pmbbo->sdef){
unsigned long *pstate_values;
short i;
pstate_values = &(pmbbo->zrvl);
pmbbo->val = udfUshort; /* initalize to unknown state*/
if(rval!=udfUlong) {
for (i = 0; i < 16; i++){
if (*pstate_values == rval){
pmbbo->val = i;
break;
}
pstate_values++;
}
}
}else{
/* the raw is the desired val */
pmbbo->val = (unsigned short)rval;
}
}
return(0);
}
@@ -188,64 +198,74 @@ static long process(paddr)
struct dbAddr *paddr;
{
struct mbboRecord *pmbbo=(struct mbboRecord *)(paddr->precord);
struct mbbodset *pdset = (struct mbbodset *)(pmbbo->dset);
long status;
unsigned short rbv;
struct mbbodset *pdset = (struct mbbodset *)(pmbbo->dset);
long status=0;
unsigned short rbv;
if( (pdset==NULL) || (pdset->write_mbbo==NULL) ) {
pmbbo->pact=TRUE;
recGblRecordError(S_dev_missingSup,pmbbo,"write_mbbo");
return(S_dev_missingSup);
if( (pdset==NULL) || (pdset->write_mbbo==NULL) ) {
pmbbo->pact=TRUE;
recGblRecordError(S_dev_missingSup,pmbbo,"write_mbbo");
return(S_dev_missingSup);
}
if (!pmbbo->pact) {
if(pmbbo->dol.type==DB_LINK && pmbbo->omsl==CLOSED_LOOP){
long options=0;
long nRequest=1;
long status;
unsigned short val;
pmbbo->pact = TRUE;
status = dbGetLink(&pmbbo->dol.value.db_link,pmbbo,DBR_USHORT,
&val,&options,&nRequest);
pmbbo->pact = FALSE;
if(status==0) {
pmbbo->val=val;
} else {
if(pmbbo->nsev < VALID_ALARM) {
pmbbo->nsev = VALID_ALARM;
pmbbo->nsta = LINK_ALARM;
}
goto DONT_WRITE;
}
}
if(pmbbo->val==udfEnum) {
if(pmbbo->nsev < VALID_ALARM) {
pmbbo->nsev = VALID_ALARM;
pmbbo->nsta = SOFT_ALARM;
}
goto DONT_WRITE;
}
if(pmbbo->sdef) {
unsigned long *pvalues = &(pmbbo->zrvl);
/* fetch the desired output if there is a database link */
if (!pmbbo->pact && pmbbo->dol.type==DB_LINK && pmbbo->omsl==CLOSED_LOOP){
long options=0;
long nRequest=1;
short savepact=pmbbo->pact;
if(pmbbo->val>15) {
if(pmbbo->nsev<VALID_ALARM ) {
pmbbo->nsta = SOFT_ALARM;
pmbbo->nsev = VALID_ALARM;
}
goto DONT_WRITE;
}
pmbbo->rval = pvalues[pmbbo->val];
} else pmbbo->rval = (unsigned long)(pmbbo->val);
if(pmbbo->shft>0) pmbbo->rval <<= pmbbo->shft;
}
pmbbo->pact = TRUE;
(void)dbGetLink(&pmbbo->dol.value.db_link,pmbbo,DBR_ENUM,
&(pmbbo->val),&options,&nRequest);
pmbbo->pact = savepact;
}
status=(*pdset->write_mbbo)(pmbbo); /* write the new value */
DONT_WRITE:
pmbbo->pact = TRUE;
status=(*pdset->write_mbbo)(pmbbo); /* write the new value */
pmbbo->pact = TRUE;
/* status is one if an asynchronous record is being processed*/
if(status==1) return(0);
/* calculate the readback value */
if (pmbbo->sdef){
unsigned long *pstate_values;
short i;
unsigned long rval = pmbbo->rval;
pstate_values = &(pmbbo->zrvl);
rbv = udfShort; /* initalize to unknown state*/
if(rval!=udfUlong) for (i = 0; i < 16; i++){
if (*pstate_values == rval){
rbv = i;
break;
}
pstate_values++;
}
}else{
/* the raw value is the desired value */
rbv = (unsigned short)(pmbbo->rval);
}
pmbbo->rbv = rbv;
/* check for alarms */
alarm(pmbbo);
/* check event list */
monitor(pmbbo);
/* process the forward scan link record */
if (pmbbo->flnk.type==DB_LINK) dbScanPassive(pmbbo->flnk.value.db_link.pdbAddr);
pmbbo->pact=FALSE;
return(status);
/* status is one if an asynchronous record is being processed*/
if(status==1) return(0);
/* check for alarms */
alarm(pmbbo);
/* check event list */
monitor(pmbbo);
/* process the forward scan link record */
if(pmbbo->flnk.type==DB_LINK)
dbScanPassive(pmbbo->flnk.value.db_link.pdbAddr);
pmbbo->pact=FALSE;
return(status);
}
static long special(paddr,after)
@@ -333,12 +353,12 @@ static void alarm(pmbbo)
struct mbboRecord *pmbbo;
{
unsigned short *severities;
short val=pmbbo->val;
unsigned short val=pmbbo->val;
/* check for state alarm */
/* unknown state */
if ((val < 0) || (val > 15)){
if (val > 15){
if (pmbbo->nsev<pmbbo->unsv){
pmbbo->nsta = STATE_ALARM;
pmbbo->nsev = pmbbo->unsv;
@@ -353,6 +373,7 @@ static void alarm(pmbbo)
}
/* check for cos alarm */
if(pmbbo->lalm==udfUshort) pmbbo->lalm = val;
if(val == pmbbo->lalm) return;
if (pmbbo->nsev<pmbbo->cosv){
pmbbo->nsta = COS_ALARM;
@@ -380,10 +401,6 @@ static void monitor(pmbbo)
pmbbo->nsta = 0;
pmbbo->nsev = 0;
/* anyone waiting for an event on this record */
if (pmbbo->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */

View File

@@ -82,25 +82,75 @@ struct rset permissiveRSET={
get_graphic_double,
get_control_double,
get_alarm_double };
void monitor();
static long process(paddr)
struct dbAddr *paddr;
{
struct permissiveRecord *ppermissive=(struct permissiveRecord *)(paddr->precord);
struct permissiveRecord *ppermissive=(struct permissiveRecord *)(paddr->precord);
ppermissive->pact=TRUE;
if(ppermissive->mlis.count!=0)
db_post_events(ppermissive,&ppermissive->val,DBE_VALUE);
ppermissive->pact=FALSE;
return(0);
ppermissive->pact=TRUE;
monitor(ppermissive);
if (ppermissive->flnk.type==DB_LINK)
dbScanPassive(ppermissive->flnk.value.db_link.pdbAddr);
ppermissive->pact=FALSE;
return(0);
}
static long get_value(ppermissive,pvdes)
struct permissiveRecord *ppermissive;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_SHORT;
pvdes->field_type = DBF_USHORT;
pvdes->no_elements=1;
(short *)(pvdes->pvalue) = &(ppermissive->val);
(unsigned short *)(pvdes->pvalue) = &(ppermissive->val);
return(0);
}
static void monitor(ppermissive)
struct permissiveRecord *ppermissive;
{
unsigned short monitor_mask;
short stat,sevr,nsta,nsev;
unsigned short val,oval,wflg,oflg;
/* get previous stat and sevr and new stat and sevr*/
stat=ppermissive->stat;
sevr=ppermissive->sevr;
nsta=ppermissive->nsta;
nsev=ppermissive->nsev;
/*set current stat and sevr*/
ppermissive->stat = nsta;
ppermissive->sevr = nsev;
ppermissive->nsta = 0;
ppermissive->nsev = 0;
/* get val,oval,wflg,oflg*/
val=ppermissive->val;
oval=ppermissive->oval;
wflg=ppermissive->wflg;
oflg=ppermissive->oflg;
/*set oval and oflg*/
ppermissive->oval = val;
ppermissive->oflg = wflg;
monitor_mask = 0;
/* alarm condition changed this scan */
if (stat!=nsta || sevr!=nsev) {
/* post events for alarm condition change*/
monitor_mask = DBE_ALARM;
/* post stat and nsev fields */
db_post_events(ppermissive,&ppermissive->stat,DBE_VALUE);
db_post_events(ppermissive,&ppermissive->sevr,DBE_VALUE);
}
if(oval != val) {
db_post_events(ppermissive,&ppermissive->val,monitor_mask|DBE_VALUE);
}
if(oflg != wflg) {
db_post_events(ppermissive,&ppermissive->wflg,monitor_mask|DBE_VALUE);
}
return;
}

View File

@@ -108,7 +108,13 @@ static long process(paddr)
long status;
ppid->pact = TRUE;
status=do_pid(ppid);
if(ppid->val>0.0 && ppid->val<udfFtest) {
if (ppid->nsev<VALID_ALARM) {
ppid->nsta = SOFT_ALARM;
ppid->nsev = VALID_ALARM;
}
status = 0;
} else status=do_pid(ppid);
if(status==1) {
ppid->pact = FALSE;
return(0);
@@ -265,10 +271,6 @@ static void monitor(ppid)
ppid->nsta = 0;
ppid->nsev = 0;
/* anyone waiting for an event on this record */
if (ppid->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -298,24 +300,30 @@ static void monitor(ppid)
ppid->alst = ppid->val;
}
/* send out monitors connected to the value field */
/* send out all monitors for value changes*/
if (monitor_mask){
db_post_events(ppid,&ppid->val,monitor_mask);
}
if(ppid->ocva != ppid->cval) {
db_post_events(ppid,&ppid->cval,monitor_mask|DBE_VALUE);
ppid->ocva = ppid->cval;
}
if(ppid->oout != ppid->out) {
db_post_events(ppid,&ppid->out,monitor_mask|DBE_VALUE);
delta = ppid->oout - ppid->out;
if(delta<0.0) delta = -delta;
if(delta > ppid->odel) {
ppid->oout = ppid->out;
monitor_mask = DBE_LOG|DBE_VALUE;
db_post_events(ppid,&ppid->out,monitor_mask);
db_post_events(ppid,&ppid->p,monitor_mask);
db_post_events(ppid,&ppid->i,monitor_mask);
db_post_events(ppid,&ppid->d,monitor_mask);
db_post_events(ppid,&ppid->ct,monitor_mask);
db_post_events(ppid,&ppid->dt,monitor_mask);
db_post_events(ppid,&ppid->err,monitor_mask);
db_post_events(ppid,&ppid->derr,monitor_mask);
}
return;
}
/* A discrete form of the PID algorithm is as follows
* M(n) = KP*(E(n) + KI*SUMi(E(i)*dT(i))
* + KD*(E(n) -E(n-1))/dT(i) + Mr
* + KD*(E(n) -E(n-1))/dT(n) + Mr
* where
* M(n) Value of manipulated variable at nth sampling instant
* KP,KI,KD Proportional, Integral, and Differential Gains
@@ -348,6 +356,9 @@ struct pidRecord *ppid;
float de; /*change in error */
float dep; /*prev change in error */
float out; /*output value */
float p; /*proportional contribution*/
float i; /*integral contribution*/
float d; /*derivative contribution*/
/* fetch the controlled value */
if (ppid->cvl.type != DB_LINK) { /* nothing to control*/
@@ -385,15 +396,18 @@ struct pidRecord *ppid;
/* compute time difference and make sure it is large enough*/
ctp = ppid->ct;
ct = tickGet();
if(ctp==ct) return(1);
if(ctp<ct) {
dt = (float)(ct-ctp);
}else { /* clock has overflowed */
dt = (unsigned long)(0xffffffff) - ctp;
dt = dt + ct + 1;
if(ctp==0) {/*this happens the first time*/
dt=0.0;
} else {
if(ctp<ct) {
dt = (float)(ct-ctp);
}else { /* clock has overflowed */
dt = (unsigned long)(0xffffffff) - ctp;
dt = dt + ct + 1;
}
dt = dt/vxTicksPerSecond;
if(dt<ppid->mdt) return(1);
}
dt = dt/vxTicksPerSecond;
if(dt<ppid->mdt) return(1);
/* get the rest of values needed */
dtp = ppid->dt;
kp = ppid->kp;
@@ -403,10 +417,11 @@ struct pidRecord *ppid;
dep = ppid->derr;
e = val - cval;
de = e - ep;
out = de;
out = out + e*dt*ki;
if(dtp!=0.0) out = out + kd*(de/dt - dep/dtp);
out = kp*out;
p = kp*de;
i = kp*e*dt*ki;
if(dtp>0.0 && dt>0.0) d = kp*kd*(de/dt - dep/dtp);
else d = 0.0;
out = p + i + d;
/* update record*/
ppid->ct = ct;
ppid->dt = dt;
@@ -414,5 +429,8 @@ struct pidRecord *ppid;
ppid->derr = de;
ppid->cval = cval;
ppid->out = out;
ppid->p = p;
ppid->i = i;
ppid->d = d;
return(0);
}

View File

@@ -87,7 +87,7 @@ struct rset selRSET={
get_control_double,
get_alarm_double };
#define SEL_MAX 6
#define SEL_MAX 12
#define SELECTED 0
#define SELECT_HIGH 1
#define SELECT_LOW 2
@@ -95,18 +95,21 @@ struct rset selRSET={
void alarm();
void monitor();
void fetch_values();
int fetch_values();
int do_sel();
static long init_record(psel)
struct selRecord *psel;
{
if(psel->inpa.type==CONSTANT) psel->a = psel->inpa.value.value;
if(psel->inpb.type==CONSTANT) psel->b = psel->inpb.value.value;
if(psel->inpc.type==CONSTANT) psel->c = psel->inpc.value.value;
if(psel->inpd.type==CONSTANT) psel->d = psel->inpd.value.value;
if(psel->inpe.type==CONSTANT) psel->e = psel->inpe.value.value;
if(psel->inpf.type==CONSTANT) psel->f = psel->inpf.value.value;
struct link *plink;
int i;
double *pvalue;
plink = &psel->inpa;
pvalue = &psel->a;
for(i=0; i<SEL_MAX; i++, plink++, pvalue++) {
if(plink->type==CONSTANT) *pvalue = plink->value.value;
}
return(0);
}
@@ -116,11 +119,12 @@ static long process(paddr)
struct selRecord *psel=(struct selRecord *)(paddr->precord);
psel->pact = TRUE;
fetch_values(psel);
if(do_sel(psel)!=0) {
if(psel->nsev<MAJOR_ALARM) {
psel->nsta = CALC_ALARM;
psel->nsev = MAJOR_ALARM;
if(fetch_values(psel)==0) {
if(do_sel(psel)!=0) {
if(psel->nsev<MAJOR_ALARM) {
psel->nsta = CALC_ALARM;
psel->nsev = MAJOR_ALARM;
}
}
}
@@ -132,7 +136,8 @@ static long process(paddr)
monitor(psel);
/* process the forward scan link record */
if (psel->flnk.type==DB_LINK) dbScanPassive(psel->flnk.value.db_link.pdbAddr);
if (psel->flnk.type==DB_LINK)
dbScanPassive(psel->flnk.value.db_link.pdbAddr);
psel->pact=FALSE;
return(0);
@@ -143,9 +148,9 @@ static long get_value(psel,pvdes)
struct selRecord *psel;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_FLOAT;
pvdes->field_type = DBF_DOUBLE;
pvdes->no_elements=1;
(float *)(pvdes->pvalue) = &psel->val;
(double *)(pvdes->pvalue) = &psel->val;
return(0);
}
@@ -209,9 +214,10 @@ static long get_alarm_double(paddr,pgd)
static void alarm(psel)
struct selRecord *psel;
{
float ftemp;
float val=psel->val;
double ftemp;
double val=psel->val;
if(val>0.0 && val<udfDtest) return;
/* if difference is not > hysterisis use lalm not val */
ftemp = psel->lalm - psel->val;
if(ftemp<0.0) ftemp = -ftemp;
@@ -260,10 +266,10 @@ static void monitor(psel)
struct selRecord *psel;
{
unsigned short monitor_mask;
float delta;
double delta;
short stat,sevr,nsta,nsev;
float *pnew;
float *pprev;
double *pnew;
double *pprev;
int i;
/* get previous stat and sevr and new stat and sevr*/
@@ -277,10 +283,6 @@ static void monitor(psel)
psel->nsta = 0;
psel->nsev = 0;
/* anyone waiting for an event on this record */
if (psel->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -313,13 +315,13 @@ static void monitor(psel)
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(psel,&psel->val,monitor_mask);
}
/* check all input fields for changes*/
for(i=0, pnew=&psel->a, pprev=&psel->la; i<6; i++, pnew++, pprev++) {
if(*pnew != *pprev) {
db_post_events(psel,pnew,monitor_mask|DBE_VALUE);
*pprev = *pnew;
}
/* check all input fields for changes*/
for(i=0, pnew=&psel->a, pprev=&psel->la; i<SEL_MAX; i++, pnew++, pprev++) {
if(*pnew != *pprev) {
db_post_events(psel,pnew,monitor_mask|DBE_VALUE);
*pprev = *pnew;
}
}
}
return;
}
@@ -327,9 +329,9 @@ static void monitor(psel)
static int do_sel(psel)
struct selRecord *psel; /* pointer to selection record */
{
float *pvalue;
double *pvalue;
struct link *plink;
float order[SEL_MAX];
double order[SEL_MAX];
unsigned short order_inx;
unsigned short i,j;
@@ -342,7 +344,7 @@ struct selRecord *psel; /* pointer to selection record */
case (SELECT_HIGH):
psel->val = *pvalue;
for (i = 0; i < SEL_MAX; i++,pvalue++){
if (*pvalue == udfFloat) continue;
if (*pvalue>0.0 && *pvalue<udfDtest) continue;
if (psel->val < *pvalue)
psel->val = *pvalue;
}
@@ -350,7 +352,7 @@ struct selRecord *psel; /* pointer to selection record */
case (SELECT_LOW):
psel->val = *pvalue;
for (i = 0; i < SEL_MAX; i++,pvalue++){
if (*pvalue == udfFloat) continue;
if (*pvalue>0.0 && *pvalue<udfDtest) continue;
if (psel->val > *pvalue)
psel->val = *pvalue;
}
@@ -360,7 +362,7 @@ struct selRecord *psel; /* pointer to selection record */
plink = &psel->inpa;
order_inx = 0;
for (i = 0; i < SEL_MAX; i++,pvalue++,plink++){
if (*pvalue == udfFloat) continue;
if (*pvalue>0.0 && *pvalue<udfDtest) continue;
if (plink->type == DB_LINK){
j = order_inx;
while ((order[j-1] > *pvalue) && (j > 0)){
@@ -386,14 +388,15 @@ struct selRecord *psel; /* pointer to selection record */
*
* fetch the values for the variables from which to select
*/
static void fetch_values(psel)
static int fetch_values(psel)
struct selRecord *psel;
{
long nRequest;
long options=0;
struct link *plink;
float *pvalue;
double *pvalue;
int i;
long status;
plink = &psel->inpa;
pvalue = &psel->a;
@@ -403,16 +406,44 @@ struct selRecord *psel;
pvalue += psel->seln;
if(plink->type==DB_LINK) {
nRequest=1;
(void)dbGetLink(&plink->value.db_link,psel,DBR_FLOAT,pvalue,&options,&nRequest);
status=dbGetLink(&plink->value.db_link,psel,DBR_DOUBLE,pvalue,&options,&nRequest);
if(status!=0) {
if(psel->nsev<VALID_ALARM) {
psel->nsev=VALID_ALARM;
psel->nsta=LINK_ALARM;
}
return(-1);
}
if(*pvalue>0.0 && *pvalue<udfDtest) {
if(psel->nsev<VALID_ALARM) {
psel->nsev=VALID_ALARM;
psel->nsta=SOFT_ALARM;
}
return(-1);
}
}
return;
return(0);
}
/* fetch all inputs*/
for(i=0; i<SEL_MAX; i++, plink++, pvalue++) {
if(plink->type==DB_LINK) {
nRequest=1;
(void)dbGetLink(&plink->value.db_link,psel,DBR_FLOAT,pvalue,&options,&nRequest);
status = dbGetLink(&plink->value.db_link,psel,DBR_DOUBLE,pvalue,&options,&nRequest);
if(status!=0) {
if(psel->nsev<VALID_ALARM) {
psel->nsev=VALID_ALARM;
psel->nsta=LINK_ALARM;
}
return(-1);
}
if(*pvalue>0.0 && *pvalue<udfDtest) {
if(psel->nsev<VALID_ALARM) {
psel->nsev=VALID_ALARM;
psel->nsta=SOFT_ALARM;
}
return(-1);
}
}
}
return;
return(0);
}

View File

@@ -83,6 +83,8 @@ struct rset stateRSET={
get_graphic_double,
get_control_double,
get_alarm_double };
void monitor();
static long process(paddr)
struct dbAddr *paddr;
@@ -90,11 +92,7 @@ static long process(paddr)
struct stateRecord *pstate=(struct stateRecord *)(paddr->precord);
pstate->pact=TRUE;
if(strncmp(pstate->oval,pstate->val,sizeof(pstate->val))) {
if(pstate->mlis.count != 0)
db_post_events(pstate,&(pstate->val[0]),DBE_VALUE);
strncpy(pstate->oval,pstate->val,sizeof(pstate->val));
}
monitor(pstate);
/* process the forward scan link record */
if (pstate->flnk.type==DB_LINK) dbScanPassive(pstate->flnk.value.db_link.pdbAddr);
pstate->pact=FALSE;
@@ -111,3 +109,40 @@ static long get_value(pstate,pvdes)
return(0);
}
static void monitor(pstate)
struct stateRecord *pstate;
{
unsigned short monitor_mask;
short stat,sevr,nsta,nsev;
/* get previous stat and sevr and new stat and sevr*/
stat=pstate->stat;
sevr=pstate->sevr;
nsta=pstate->nsta;
nsev=pstate->nsev;
/*set current stat and sevr*/
pstate->stat = nsta;
pstate->sevr = nsev;
pstate->nsta = 0;
pstate->nsev = 0;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
if (stat!=nsta || sevr!=nsev) {
/* post events for alarm condition change*/
monitor_mask = DBE_ALARM;
/* post stat and nsev fields */
db_post_events(pstate,&pstate->stat,DBE_VALUE);
db_post_events(pstate,&pstate->sevr,DBE_VALUE);
}
if(strncmp(pstate->oval,pstate->val,sizeof(pstate->val))) {
if(pstate->mlis.count != 0)
db_post_events(pstate,&(pstate->val[0]),monitor_mask|DBE_VALUE);
strncpy(pstate->oval,pstate->val,sizeof(pstate->val));
}
return;
}

View File

@@ -1,7 +1,7 @@
/* recSm.c */
/* recSteppermotor.c */
/* share/src/rec $Id$ */
/* recSm.c - Record Support Routines for Steppermotor records
/* recSteppermotor.c - Record Support Routines for Steppermotor records
*
* Author: Bob Dalesio
* Date: 12-11-89
@@ -55,7 +55,7 @@
#include <link.h>
#include <recSup.h>
#include <special.h>
#include <smRecord.h>
#include <steppermotorRecord.h>
#include <steppermotor.h>
/* Create RSET - Record Support Entry Table*/
@@ -77,7 +77,7 @@ long get_graphic_double();
long get_control_double();
long get_alarm_double();
struct rset smRSET={
struct rset steppermotorRSET={
RSETNUMBER,
report,
initialize,
@@ -117,7 +117,7 @@ void sm_get_position();
static long init_record(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
init_sm(psm);
@@ -128,7 +128,7 @@ static long init_record(psm)
static long process(paddr)
struct dbAddr *paddr;
{
struct smRecord *psm=(struct smRecord *)(paddr->precord);
struct steppermotorRecord *psm=(struct steppermotorRecord *)(paddr->precord);
/* intialize the stepper motor record when the init bit is 0 */
/* the init is set when the readback returns */
@@ -156,7 +156,7 @@ static long process(paddr)
}
static long get_value(psm,pvdes)
struct smRecord *psm;
struct steppermotorRecord *psm;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_FLOAT;
@@ -169,7 +169,7 @@ static long get_units(paddr,units)
struct dbAddr *paddr;
char *units;
{
struct smRecord *psm=(struct smRecord *)paddr->precord;
struct steppermotorRecord *psm=(struct steppermotorRecord *)paddr->precord;
strncpy(units,psm->egu,sizeof(psm->egu));
return(0);
@@ -179,7 +179,7 @@ static long get_precision(paddr,precision)
struct dbAddr *paddr;
long *precision;
{
struct smRecord *psm=(struct smRecord *)paddr->precord;
struct steppermotorRecord *psm=(struct steppermotorRecord *)paddr->precord;
*precision = psm->prec;
return(0);
@@ -189,7 +189,7 @@ static long get_graphic_double(paddr,pgd)
struct dbAddr *paddr;
struct dbr_grDouble *pgd;
{
struct smRecord *psm=(struct smRecord *)paddr->precord;
struct steppermotorRecord *psm=(struct steppermotorRecord *)paddr->precord;
pgd->upper_disp_limit = psm->hopr;
pgd->lower_disp_limit = psm->lopr;
@@ -200,7 +200,7 @@ static long get_control_double(paddr,pcd)
struct dbAddr *paddr;
struct dbr_ctrlDouble *pcd;
{
struct smRecord *psm=(struct smRecord *)paddr->precord;
struct steppermotorRecord *psm=(struct steppermotorRecord *)paddr->precord;
pcd->upper_ctrl_limit = psm->hopr;
pcd->lower_ctrl_limit = psm->lopr;
@@ -211,7 +211,7 @@ static long get_alarm_double(paddr,pad)
struct dbAddr *paddr;
struct dbr_alDouble *pad;
{
struct smRecord *psm=(struct smRecord *)paddr->precord;
struct steppermotorRecord *psm=(struct steppermotorRecord *)paddr->precord;
pad->upper_alarm_limit = psm->hihi;
pad->upper_warning_limit = psm->high;
@@ -222,7 +222,7 @@ static long get_alarm_double(paddr,pad)
static void alarm(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
float deviation;
@@ -268,7 +268,7 @@ static void alarm(psm)
}
static void monitor(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
unsigned short monitor_mask;
float delta;
@@ -285,12 +285,6 @@ static void monitor(psm)
psm->nsta = 0;
psm->nsev = 0;
/* anyone waiting for an event on this record */
if (psm->mlis.count == 0) {
psm->mlst = psm->alst = psm->val;
return;
}
/* Flags which events to fire on the value field */
monitor_mask = 0;
@@ -335,7 +329,7 @@ static void monitor(psm)
*/
static void smcb_callback(psm_data,psm)
struct motor_data *psm_data;
struct smRecord *psm;
struct steppermotorRecord *psm;
{
short stat,sevr,nsta,nsev;
@@ -467,7 +461,7 @@ struct smRecord *psm;
* INIT_SM
*/
static void init_sm(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
int acceleration,velocity;
short card,channel;
@@ -546,7 +540,7 @@ struct smRecord *psm;
*
*/
static void convert_sm(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
double temp;
@@ -570,7 +564,7 @@ struct smRecord *psm;
* control a stepper motor through position
*/
static void positional_sm(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
short card,channel;
@@ -677,7 +671,7 @@ struct smRecord *psm;
* control a velocity stepper motor
*/
static void velocity_sm(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
float chng_vel;
int acceleration,velocity;
@@ -764,7 +758,7 @@ struct smRecord *psm;
* get the stepper motor readback position
*/
static void sm_get_position(psm)
struct smRecord *psm;
struct steppermotorRecord *psm;
{
short reset;
float new_pos,delta;

View File

@@ -87,10 +87,11 @@ struct rset subRSET={
get_control_double,
get_alarm_double };
#define ARG_MAX 12
void alarm();
void monitor();
long do_sub();
void fetch_values();
long fetch_values();
static long init_record(psub)
struct subRecord *psub;
@@ -100,14 +101,15 @@ static long init_record(psub)
char temp[40];
long status;
STATUS ret;
struct link *plink;
int i;
double *pvalue;
if(psub->inpa.type==CONSTANT) psub->a = psub->inpa.value.value;
if(psub->inpb.type==CONSTANT) psub->b = psub->inpb.value.value;
if(psub->inpc.type==CONSTANT) psub->c = psub->inpc.value.value;
if(psub->inpd.type==CONSTANT) psub->d = psub->inpd.value.value;
if(psub->inpe.type==CONSTANT) psub->e = psub->inpe.value.value;
if(psub->inpf.type==CONSTANT) psub->f = psub->inpf.value.value;
plink = &psub->inpa;
pvalue = &psub->a;
for(i=0; i<ARG_MAX; i++, plink++, pvalue++) {
if(plink->type==CONSTANT) *pvalue = plink->value.value;
}
/* convert the initialization subroutine name */
temp[0] = 0; /* all global variables start with _ */
@@ -145,14 +147,14 @@ static long process(paddr)
struct dbAddr *paddr;
{
struct subRecord *psub=(struct subRecord *)(paddr->precord);
long status;
long status=0;
if(!psub->pact){
psub->pact = TRUE;
fetch_values(psub);
status = fetch_values(psub);
psub->pact = FALSE;
}
status = do_sub(psub);
if(status==0) status = do_sub(psub);
psub->pact = TRUE;
if(status==1) return(0);
/* check for alarms */
@@ -169,9 +171,9 @@ static long get_value(psub,pvdes)
struct subRecord *psub;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_FLOAT;
pvdes->field_type = DBF_DOUBLE;
pvdes->no_elements=1;
(float *)(pvdes->pvalue) = &psub->val;
(double *)(pvdes->pvalue) = &psub->val;
return(0);
}
@@ -234,9 +236,10 @@ static long get_alarm_double(paddr,pad)
static void alarm(psub)
struct subRecord *psub;
{
float ftemp;
float val=psub->val;
double ftemp;
double val=psub->val;
if(val>0.0 && val<udfDtest)return;
/* if difference is not > hysterisis use lalm not val */
ftemp = psub->lalm - psub->val;
if(ftemp<0.0) ftemp = -ftemp;
@@ -287,10 +290,10 @@ static void monitor(psub)
struct subRecord *psub;
{
unsigned short monitor_mask;
float delta;
double delta;
short stat,sevr,nsta,nsev;
float *pnew;
float *pprev;
double *pnew;
double *pprev;
int i;
/* get previous stat and sevr and new stat and sevr*/
@@ -304,10 +307,6 @@ static void monitor(psub)
psub->nsta = 0;
psub->nsev = 0;
/* anyone waiting for an event on this record */
if (psub->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
@@ -339,33 +338,48 @@ static void monitor(psub)
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(psub,&psub->val,monitor_mask);
}
/* check all input fields for changes*/
for(i=0, pnew=&psub->a, pprev=&psub->la; i<6; i++, pnew++, pprev++) {
if(*pnew != *pprev) {
db_post_events(psub,pnew,monitor_mask|DBE_VALUE);
*pprev = *pnew;
/* check all input fields for changes*/
for(i=0, pnew=&psub->a, pprev=&psub->la; i<ARG_MAX; i++, pnew++, pprev++) {
if(*pnew != *pprev) {
db_post_events(psub,pnew,monitor_mask|DBE_VALUE);
*pprev = *pnew;
}
}
}
}
return;
}
static void fetch_values(psub)
static long fetch_values(psub)
struct subRecord *psub;
{
struct link *plink; /* structure of the link field */
float *pvalue;
double *pvalue;
long options,nRequest;
int i;
long status;
for(i=0, plink=&psub->inpa, pvalue=&psub->a; i<6; i++, plink++, pvalue++) {
for(i=0, plink=&psub->inpa, pvalue=&psub->a; i<ARG_MAX; i++, plink++, pvalue++) {
if(plink->type!=DB_LINK) continue;
options=0;
nRequest=1;
(void)dbGetLink(&plink->value.db_link,psub,DBR_FLOAT,
status=dbGetLink(&plink->value.db_link,psub,DBR_DOUBLE,
pvalue,&options,&nRequest);
if(status!=0) {
if(psub->nsev<VALID_ALARM) {
psub->nsev=VALID_ALARM;
psub->nsta=LINK_ALARM;
}
return(-1);
}
if(*pvalue>0.0 && *pvalue<udfDtest) {
if(psub->nsev<VALID_ALARM) {
psub->nsev=VALID_ALARM;
psub->nsta=SOFT_ALARM;
}
return(-1);
}
}
return;
return(0);
}
static long do_sub(psub)
@@ -378,9 +392,9 @@ struct subRecord *psub; /* pointer to subroutine record */
/* call the subroutine */
psubroutine = (FUNCPTR)(psub->sadr);
if(psubroutine==NULL) {
if(psub->nsev<MAJOR_ALARM) {
if(psub->nsev<VALID_ALARM) {
psub->nsta = BAD_SUB_ALARM;
psub->nsev = MAJOR_ALARM;
psub->nsev = VALID_ALARM;
}
return(0);
}

View File

@@ -116,7 +116,6 @@ static long init_record(ptimer)
return(0);
}
static long process(paddr)
struct dbAddr *paddr;
{
@@ -145,7 +144,7 @@ static long get_value(ptimer,pvdes)
(short *)(pvdes->pvalue) = &ptimer->val;
return(0);
}
static void monitor(ptimer)
struct timerRecord *ptimer;
{
@@ -163,9 +162,6 @@ static void monitor(ptimer)
ptimer->nsta = 0;
ptimer->nsev = 0;
/* anyone waiting for an event on this record */
if (ptimer->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
@@ -190,7 +186,7 @@ static void monitor(ptimer)
* These constants are indexed by the time units field in the timer record.
* Values are converted to seconds.
*/
static double constants[] = {1000,1000000,1000000000,1000000000000};
static double constants[] = {1e3,1e6,1e9,1e12};
/*
* CONVERT_TIMER
*

View File

@@ -295,9 +295,6 @@ static void monitor(pwf)
pwf->nsta = 0;
pwf->nsev = 0;
/* anyone waiting for an event on this record */
if(pwf->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
@@ -309,7 +306,7 @@ static void monitor(pwf)
db_post_events(pwf,&pwf->stat,DBE_VALUE);
db_post_events(pwf,&pwf->sevr,DBE_VALUE);
}
monitor_mask |= DBE_LOG|DBE_VALUE;
monitor_mask |= (DBE_LOG|DBE_VALUE);
if(monitor_mask) db_post_events(pwf,pwf->bptr,monitor_mask);
return;