/* $Id: fcomrtst.c,v 1.3 2009/07/28 22:59:38 strauman Exp $ */ /* Test program for FCOM receiver * * Author: Till Straumann , 2009. * * Reads ASCII file from stdin (in fcom_get_blob_from_file() format, * see fcomP.h) and subscribes all IDs found. * Then (depending on implemented features) it either * EITHER repeatedly executes fcom_receiver() until the subscribed number * of blobs has been processed. * OR sleeps for 'timeout' amount while data are received in the * background. * OR performs a synchronous fcomGetBlob() on the LAST ID * * At this point, all data sent by a concurrently running 'fcomxtst' * should be processed and this program executes (asynchronous) * 'fcomGetBlob()' for all IDs and subsequently writes them to * an ASCII file. */ #include #include #include #include #include #include #define BLOBSZ 1000 #define NUMID 100 int main(int argc, char **argv) { int st; int rval = 1; FcomBlobRef pb = malloc(BLOBSZ); int err; FILE *infile = stdin; FILE *outfile = stdout; FcomBlobRef pb1; FcomID ids[NUMID]; int nids = 0, nblobs = 0; int i; unsigned tout=10000; #if !defined(USE_EPICS) && !defined(USE_PTHREADS) int got; #else struct timespec touts; #endif int have_sync; while ( (i=getopt(argc, argv, "t:")) > 0 ) { switch (i) { case 't': if ( 1 != sscanf(optarg,"%u",&tout) ) { fprintf(stderr,"Number expected as '-t' argument\n"); return 1; } break; case 'h': default: fprintf(stderr,"Usage: %s [-t 0 ) { if ( nids < NUMID ) { if ( (st = fcomSubscribe(ids[nids] = pb->fc_idnt, have_sync)) ) { fprintf(stderr,"fcomSubscribe() failed: %s\n", fcomStrerror(st)); } else { nids++; } } nblobs++; } #if 0 /* Commented this test: there could be repeated definitions for as single ID * in the file... */ if ( nblobs != nids ) fprintf(stderr,"Warning: Not all blobs (# %u) subscribed (# %u)\n",nblobs, nids); #endif #if !defined(USE_EPICS) && !defined(USE_PTHREADS) for ( i=0; i 0 ) { fprintf(stderr,"Blocking for data...\n"); st = fcomGetBlob(ids[nids-1], &pb1, tout); if ( st ) { fprintf(stderr,"ERROR: %s\n", fcomStrerror(st)); goto bail; } fprintf(stderr,"...got it!\n"); fcomReleaseBlob(&pb1); } } #endif for ( i=0; i