From 25b4959f3f6cde8eac4a48dced6467fa62311b68 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Fri, 9 Jun 2000 12:48:10 +0000 Subject: [PATCH] added caMonitor --- src/makeBaseApp/top/exampleApp/src/Makefile | 1 + .../top/exampleApp/src/caMonitor.c | 119 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/makeBaseApp/top/exampleApp/src/caMonitor.c diff --git a/src/makeBaseApp/top/exampleApp/src/Makefile b/src/makeBaseApp/top/exampleApp/src/Makefile index 182c87086..2145c4160 100644 --- a/src/makeBaseApp/top/exampleApp/src/Makefile +++ b/src/makeBaseApp/top/exampleApp/src/Makefile @@ -51,6 +51,7 @@ Com_DIR = $(EPICS_BASE_LIB) example_SRCS += xxxRecord.c example_SRCS += devXxxSoft.c +example_SRCS += caMonitor.c example_SRCS_DEFAULT += registerRecordDeviceDriver.c example_SRCS_DEFAULT += exampleMain.c diff --git a/src/makeBaseApp/top/exampleApp/src/caMonitor.c b/src/makeBaseApp/top/exampleApp/src/caMonitor.c new file mode 100644 index 000000000..8008614d5 --- /dev/null +++ b/src/makeBaseApp/top/exampleApp/src/caMonitor.c @@ -0,0 +1,119 @@ +/*caMonitor.c*/ +/* This example accepts a file containing a list of pvs to monitor + * It prints a message for all ca evemts: connection, access rights, data + */ +#include +#include +#include +#include + +#include "osiThread.h" +#include "tsStamp.h" +#include "cadef.h" +#include "dbDefs.h" + +#define MAX_PV 1000 +#define MAX_PV_NAME_LEN 40 + +typedef struct{ + char value[20]; + chid mychid; + evid myevid; +} MYNODE; + + +static void printChidInfo(chid chid, char *message) +{ + printf("\n%s\n",message); + printf("pv: %s type(%d) nelements(%ld) host(%s)", + ca_name(chid),ca_field_type(chid),ca_element_count(chid), + ca_host_name(chid)); + printf(" read(%d) write(%d) state(%d)\n", + ca_read_access(chid),ca_write_access(chid),ca_state(chid)); +} + +static void exceptionCallback(struct exception_handler_args args) +{ + chid chid = args.chid; + long stat = args.stat; /* Channel access status code*/ + const char *channel; + static char *noname = "unknown"; + + channel = (chid ? ca_name(chid) : noname); + + + if(chid) printChidInfo(chid,"exceptionCallback"); + printf("exceptionCallback stat %s channel %s\n", + ca_message(stat),channel); +} + +static void connectionCallback(struct connection_handler_args args) +{ + chid chid = args.chid; + + printChidInfo(chid,"connectionCallback"); +} + +static void accessRightsCallback(struct access_rights_handler_args args) +{ + chid chid = args.chid; + + printChidInfo(chid,"accessRightsCallback"); +} +static void eventCallback(struct event_handler_args eha) +{ + chid chid = eha.chid; + + if(eha.status!=ECA_NORMAL) { + printChidInfo(chid,"eventCallback"); + } else { + char *pdata = (char *)eha.dbr; + printf("Event Callback: %s = %s\n",ca_name(eha.chid),pdata); + } +} + +int caMonitor(char *filename) +{ + int npv = 0; + MYNODE *pmynode[MAX_PV]; + char *pname[MAX_PV]; + int i; + char tempStr[MAX_PV_NAME_LEN]; + char *pstr; + FILE *fp; + + fp = fopen(filename,"r"); + if(!fp) { + perror("fopen failed"); + return(1); + } + while(1) { + if(npv >= MAX_PV ) break; + pstr = fgets(tempStr,MAX_PV_NAME_LEN,fp); + if(!pstr) break; + if(strlen(pstr) <=1) continue; + pstr[strlen(pstr)-1] = '\0'; /*strip off newline*/ + pname[npv] = calloc(1,strlen(pstr) + 1); + strcpy(pname[npv],pstr); + pmynode[npv] = (MYNODE *)calloc(1,sizeof(MYNODE)); + npv++; + } + SEVCHK(ca_task_initialize(),"ca_task_initialize"); + SEVCHK(ca_add_exception_event(exceptionCallback,NULL), + "ca_add_exception_event"); + for(i=0; imychid, + connectionCallback,&pmynode[i]), + "ca_search_and_connect"); + SEVCHK(ca_replace_access_rights_event(pmynode[i]->mychid, + accessRightsCallback), + "ca_replace_access_rights_event"); + SEVCHK(ca_add_event(DBR_STRING,pmynode[i]->mychid,eventCallback, + pmynode[i],&pmynode[i]->myevid), + "ca_add_event"); + } + /*Should never return from following call*/ + SEVCHK(ca_pend_event(0.0),"ca_pend_event"); + ca_task_exit(); + return(0); +}