int main(int argc, char *argv[]) { host_t host; /* these variables are for the threading */ int rc; pthread_t tid; check_datatypes(); if (argc>2) { sprintf(host.name, argv[1]); host.port = atoi(argv[2]); } else { sprintf(host.name, DEFAULT_HOSTNAME); host.port = DEFAULT_PORT; } fprintf(stderr, "demo_sinewave: host.name = %s\n", host.name); fprintf(stderr, "demo_sinewave: host.port = %d\n", host.port); /* start the acquisition */ sinewave_thread((void *)(&host)); return 0; }
int main(int argc, char *argv[]) { host_t host; #ifndef PLATFORM_WIN32 sigset_t sigInt; #endif int errval, blocksize; /* verify that all datatypes have the expected syze in bytes */ check_datatypes(); strcpy(host.name, DEFAULT_HOSTNAME); if (argc>1) { host.port = atoi(argv[1]); } else { host.port = DEFAULT_PORT; } if (argc>2) { blocksize = atoi(argv[2]); } else { blocksize = 0; } if (host.port <= 0 || blocksize < 0) { fprintf(stderr, "Usage: buffer_rda [port [blocksize]]\nPort number must be positive, block size must be >= 0.\n"); return 1; } #ifndef PLATFORM_WIN32 /* Make sure the RDA server thread does not receive CTRL-C, instead it will get terminated properly using rda_stop_server from a handler. We need this because otherwise it is unspecified in which thread the signal will be received - the thread created in rda_start_server will inherit the signal mask we temporarily modify here. */ sigemptyset(&sigInt); sigaddset(&sigInt, SIGINT); sigprocmask(SIG_BLOCK, &sigInt, NULL); #endif /* 0,0,0 = dma-connection to fieldtrip, default = float, default port */ rdac = rda_start_server(0, 0, 0, blocksize, &errval); if (errval != 0) { printf("Could not start rdaserver: %i\n", errval); return errval; } rdac->verbosity = 6; #ifndef PLATFORM_WIN32 /* We want CTRL-C in this thread */ sigprocmask(SIG_UNBLOCK, &sigInt, NULL); #endif signal(SIGINT, abortHandler); /* start the buffer */ tcpserver((void *)(&host)); return 0; }
int main(int argc, char *argv[]) { int port; char *name = NULL; /* verify that all datatypes have the expected syze in bytes */ check_datatypes(); if (argc>1) { port = atoi(argv[1]); if (port == 0) { name = argv[1]; } } else { port = 1972; } /* with enabled debug output */ S = ft_start_buffer_server(port, name, my_request_handler, NULL); /* plain server without extra output */ /* S = ft_start_buffer_server(port, name, NULL, NULL); */ if (S==NULL) return 1; signal(SIGINT, abortHandler); while (keepRunning) { usleep(1000000); } printf("Ctrl-C pressed -- stopping buffer server...\n"); ft_stop_buffer_server(S); printf("Done.\n"); return 0; }
int main(int argc, char *argv[]) { host_t host; /* verify that all datatypes have the expected syze in bytes */ check_datatypes(); sprintf(host.name, DEFAULT_HOSTNAME); if (argc>1) { host.port = atoi(argv[1]); } else { printf("Using default port, recommended usage 'buffer [port]'. \n"); host.port = DEFAULT_PORT; } /* start the buffer */ printf("Starting FieldTrip buffer on port %d... \n", host.port); tcpserver((void *)(&host)); return 0; }
int main(int argc, char *argv[]) { host_t host; check_datatypes(); if (argc>2) { sprintf(host.name, argv[1]); host.port = atoi(argv[2]); } else { sprintf(host.name, DEFAULT_HOSTNAME); host.port = DEFAULT_PORT; } fprintf(stderr, "demo_event: host.name = %s\n", host.name); fprintf(stderr, "demo_event: host.port = %d\n", host.port); /* start the acquisition */ event_thread((void *)(&host)); return 0; }
int main(int argc, char *argv[]) { int port; char *name = NULL; union { short word; char bytes[2]; } endianTest; endianTest.bytes[0] = 1; endianTest.bytes[1] = 0; if (endianTest.word == 1) { strcpy(endianness, "little"); } else { strcpy(endianness, "big"); } /* verify that all datatypes have the expected syze in bytes */ check_datatypes(); #ifdef WIN32 timeBeginPeriod(1); #endif if (argc<2) { fprintf(stderr, "Usage: recording <directory> [port/unix socket]\n"); return 1; } strncpy(baseDirectory, argv[1], sizeof(baseDirectory)); if (argc>2) { port = atoi(argv[2]); if (port == 0) { name = argv[2]; } } else { port = 1972; } memset(queue, sizeof(queue), 0); if (!write_contents()) goto cleanup; S = ft_start_buffer_server(port, name, my_request_handler, NULL); if (S==NULL) return 1; signal(SIGINT, abortHandler); while (keepRunning) { if (queue[qReadPos].command == 0) { usleep(1000); } else { switch(queue[qReadPos].command) { case PUT_HDR: if (setCounter>0) ft_storage_close(OS); write_header_to_disk(); if (OS==NULL) { fprintf(stderr, "!!!!!!!!!!!!! WARNING !!!!!!!!!!\n"); fprintf(stderr, "!! will NOT save this dataset !!\n"); fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); } break; case PUT_DAT: if (OS) write_samples_to_disk(queue[qReadPos].quantity, queue[qReadPos].t); break; case PUT_EVT: if (OS) write_events_to_disk(queue[qReadPos].quantity, queue[qReadPos].t); break; } queue[qReadPos].command = 0; if (++qReadPos == QUEUE_SIZE) qReadPos = 0; } } printf("Ctrl-C pressed -- stopping buffer server...\n"); if (setCounter>0 && OS!=NULL) ft_storage_close(OS); ft_stop_buffer_server(S); printf("Done.\n"); cleanup: #ifdef WIN32 timeEndPeriod(1); #endif return 0; }
int main(int argc, char *argv[]) { host_t host; /* these variables are for the threading */ int rc; pthread_t tid; /* these variables are for writing the data */ int i, j, k, status = 0, verbose = 0, samplecount = 0; time_t tic, toc; time_t elapsed; /* these represent the acquisition system properties */ int fsample = 512; /* this is just for the header */ int nchans = 32; int nsamples = 64; int stateless = 0; /* boolean */ /* these are used in the communication and represent statefull information */ int server = -1; message_t *request = NULL; message_t *response = NULL; header_t *header = NULL; data_t *data = NULL; event_t *event = NULL; /* start with defaults */ sprintf(host.name, DEFAULT_HOSTNAME); host.port = DEFAULT_PORT; if (argc>1) sprintf(host.name, argv[1]); if (argc>2) host.port = atoi(argv[2]); if (argc>3) nchans = atoi(argv[3]); if (argc>4) nsamples = atoi(argv[4]); if (argc>5) stateless = atoi(argv[5]); check_datatypes(); if (verbose>0) fprintf(stderr, "test_benchmark: host.name = %s\n", host.name); if (verbose>0) fprintf(stderr, "test_benchmark: host.port = %d\n", host.port); /* allocate the elements that will be used in the communication */ request = malloc(sizeof(message_t)); request->def = malloc(sizeof(messagedef_t)); request->buf = NULL; request->def->version = VERSION; request->def->bufsize = 0; header = malloc(sizeof(header_t)); header->def = malloc(sizeof(headerdef_t)); header->buf = NULL; data = malloc(sizeof(data_t)); data->def = malloc(sizeof(datadef_t)); data->buf = NULL; event = malloc(sizeof(event_t)); event->def = malloc(sizeof(eventdef_t)); event->buf = NULL; /* define the header */ header->def->nchans = nchans; header->def->nsamples = 0; header->def->nevents = 0; header->def->fsample = fsample; header->def->data_type = DATATYPE_FLOAT32; header->def->bufsize = 0; FREE(header->buf); /* define the constant part of the data and allocate space for the variable part */ data->def->nchans = nchans; data->def->nsamples = nsamples; data->def->data_type = DATATYPE_FLOAT32; data->def->bufsize = WORDSIZE_FLOAT32*nchans*nsamples; FREE(data->buf); data->buf = malloc(WORDSIZE_FLOAT32*nchans*nsamples); /* create the random data */ for (j=0; j<nsamples; j++) for (i=0; i<nchans; i++) ((FLOAT32_T *)(data->buf))[j*nchans+i] = 2.0*((FLOAT32_T)rand())/RAND_MAX - 1.0; /* initialization phase, send the header */ request->def->command = PUT_HDR; request->def->bufsize = append(&request->buf, request->def->bufsize, header->def, sizeof(headerdef_t)); request->def->bufsize = append(&request->buf, request->def->bufsize, header->buf, header->def->bufsize); server = open_connection(host.name, host.port); status = clientrequest(server, request, &response); if (verbose>0) fprintf(stderr, "test_benchmark: clientrequest returned %d\n", status); if (status) { fprintf(stderr, "random: err1\n"); goto cleanup; } if (stateless) { status = close_connection(server); if (status) { fprintf(stderr, "random: err2\n"); goto cleanup; } } cleanup_message(&request); cleanup_message(&response); request = NULL; response = NULL; tic = time(NULL); while (1) { /* create the request */ request = malloc(sizeof(message_t)); request->def = malloc(sizeof(messagedef_t)); request->buf = NULL; request->def->version = VERSION; request->def->bufsize = 0; request->def->command = PUT_DAT; request->def->bufsize = append(&request->buf, request->def->bufsize, data->def, sizeof(datadef_t)); request->def->bufsize = append(&request->buf, request->def->bufsize, data->buf, data->def->bufsize); if (stateless) server = open_connection(host.name, host.port); status = clientrequest(server, request, &response); if (verbose>0) fprintf(stderr, "random: clientrequest returned %d\n", status); if (status) { fprintf(stderr, "random: err3\n"); goto cleanup; } if (stateless) { status = close_connection(server); if (status) { fprintf(stderr, "random: err4\n"); goto cleanup; } } cleanup_message(&request); cleanup_message(&response); request = NULL; response = NULL; samplecount += nsamples*nchans; toc = time(NULL); elapsed = toc-tic; fprintf(stderr, "samplecount = %d, elapsed = %d, samples/sec = %f\n", samplecount, elapsed, ((float)(samplecount))/((float)elapsed)); } /* while(1) */ cleanup: cleanup_event(&event); cleanup_data(&data); cleanup_header(&header); cleanup_message(&request); cleanup_message(&response); pthread_exit(0); return 0; }