/*************************************************************************\ * 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. \*************************************************************************/ /* * * H A N D S H A K E * * Jeff Hill 4-10-90 * * An example CA client which handshakes with another copy of itself * * BEGIN PROGRAM A * DO FOREVER * signal program B * WAIT for a signal from B * END DO * * BEGIN PROGRAM B * DO FOREVER * signal program A * WAIT for a signal from A * END DO * * * * NOTE: the need to flush out the put in listen_event() * * * * * * */ #include #include #include #define USAGE "usage: handshake " #ifdef vxWorks #define abort taskSuspend #endif chid listenid; chid replyid; int handshake(char *listen, char*reply); void listen_event(struct event_handler_args args); #ifndef vxWorks main(int argc, char **argv) { char *listen; char *reply; if(argc!=3){ printf("%s\n",USAGE); exit(-1); } listen = argv[1]; reply = argv[2]; return handshake (listen, reply); } #endif int handshake(char *listen, char*reply) { int status; if( !(listen && reply) ){ printf("%s\n",USAGE); exit(-1); } /* * * Initialize CA * */ SEVCHK(ca_task_initialize(),"Unable to initialize"); /* * get the channel id's */ status = ca_search( listen, /* channel ASCII name */ &listenid /* ptr to chid */ ); SEVCHK(status, "Bad Channel Name?") status = ca_search( reply, /* channel ASCII name */ &replyid /* ptr to chid */ ); SEVCHK(status, "Bad Channel Name?") /* * * Wait for CA to find the channels * */ status = ca_pend_io(1.0); SEVCHK(status, NULL) /* * * Run listen event each time the listen channel changes * */ status = ca_add_event( DBR_INT, listenid, listen_event, NULL, NULL); SEVCHK(status, NULL); /* * Wait forever */ status = ca_pend_event(0.0); SEVCHK(status, NULL); return 0; } void listen_event(struct event_handler_args args) { unsigned short i; int status; static int count; /* * Incrementing the value is important since there * must be a significant change */ i = 100 + *(unsigned short *)args.dbr; status = ca_put(DBR_INT,replyid,&i); SEVCHK(status,NULL); /* * The put is not sent until I flush the send buffer * */ status = ca_flush_io(); SEVCHK(status,NULL); if(count++ > 100){ count=0; printf("sent one hundred\n"); } }