/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* This program puts the values to IOC channels It reads an input file which contains a list of channel_name & string_value and puts the specified STRING_VALUE into the channel. It can also accept input from the pipe */ #define DB_TEXT_GLBLSOURCE #include "chandata.h" static struct stat buf; extern chandata *pchandata; char *str; int *off_loc, *value_loc; chid *pchid; int readPutValue(); void caPutStringArray(); void caPut_help(); void caPut_exit(); char *caPut_readFile0(); char *caPut_readPipe(); float list_io_time=10.; extern char *optarg; extern int optind; extern int getopt(); extern int fileno(); extern ssize_t read(); int main(argc,argv) int argc; char **argv; { int noName,c; while ((c = getopt(argc,argv,"w:")) != -1) switch (c) { case 'w': list_io_time = (float)atof(optarg); if (list_io_time < 10.) list_io_time = 10.; break; } if (argc == 1 || argv[optind] == NULL ) str = (char *)caPut_readPipe(&noName); else str = (char *)caPut_readFile0(argv[optind],&noName); off_loc = (int *)calloc(noName+1,sizeof(int)); value_loc = (int *)calloc(noName+1,sizeof(int)); pchid = (chid *)calloc(noName+1,sizeof(chid)); if (value_loc == NULL || off_loc == NULL || pchid == NULL) { printf("Error: alloc failed on value,value_string,pchid\n"); caPut_exit(1); } noName = readPutValue(str,off_loc,value_loc); caPutStringArray(noName,str,off_loc,value_loc,pchid); printf(" *** caPut completed normally ***\n"); caPut_exit(0); } void caPut_help() { printf("\nUsage: caPut1 [-w sec] \n\n"); printf("This tool puts the set values to IOC channels. It reads an input \n"); printf("file which contains a list of pair values of channel_name & set_value\n"); printf("and puts the set_values into IOC through CA call. The set_value\n"); printf("must be in DBR_STRING form as created by caGet1.\n\n"); printf(" [-w sec] - Option to override the default timeout wait time, \n"); printf(" default wait time is 10 seconds.\n"); printf(" - Required, which contains a list of lines, each line\n"); printf(" consists of a channel name and the corresponding value\n"); printf(" to be put to IOC. \n\n"); exit(1); } void caPut_exit(i) int i; { free(str); free(off_loc); free(value_loc); free(pchid); } void caPutStringArray(noName,str,off_loc,value_loc,pchid) int noName; char *str; int *off_loc,*value_loc; chid *pchid; { int i; ca_task_initialize(); for (i=0;i 0) { ca_put(DBR_STRING,pchid[i],(str+value_loc[i])); printf("%-30s %s\n",str+off_loc[i],str+value_loc[i]); } } else printf("%-30s *** NOT FOUND / NOT CONNECTED ***\n", str+off_loc[i]); ca_flush_io(); ca_task_exit(); } int readPutValue(ptr,off_loc,value_loc) char *ptr; int *off_loc,*value_loc; { int l,i; l = 0; for (i=0;i