/* vnarec3d.c Measurement server for the EMCAR system. This code employs code from the: Simplest possible DI-194(RS) test program Paul Hubbard 4/2/03 2006-11-27 Bob Freeman Hacked Pauls code to read faster for making recordings from the hp8410b network analyzer (removed time_t calls) 2007-12-30 Bob Freeman Extended hack to add IPC functions needed to synchronize with the Ham Antenna Range system being developed on the EMC2 system. Notes are included below as planning proceeds. Sure hope a real programmer gets ahold of this. raf 2007-01-29 Bob Freeman Added some functionality for calls to a realtime plot via gnuplot "This software uses the gnuplot_i library written by N.Devillard and updating the plot via a replot command at each IPC call */ #include #include #include #include #include #include "di194.h" #include "vnarec3d.h" #include "gnuplot_i.h" // include interactive gnuplot interface // from server.c (Mark Watson) #include #include #include #include #include // Global boolean set by signal handler to force exit bool do_exit; // socket programming variables int port = 8000; // socket port number struct sockaddr_in srv; struct sockaddr_in pin; int sock_descriptor; int temp_sock_descriptor; int address_size; char buf[BUFSIZE]; int i, len; int rc; daq_reading_t data; int DI_FD = -1; int num_bits = 8; void sighandler(int signal); /* Open files pointers */ FILE *fp_1; // ====================================================================== int main(int argc, char *argv[]) { // initialize gnulot_i gnuplot_ctrl * g ; g = gnuplot_init(); //char vnafile[]="/home/bob/vna.dat"; char myfile[]="/home/bob/polar40dB.gnu"; char stepfile[]="/home/bob/polar40dB_step.gnu"; // Open the Signal Handler printf("\nInstalling signal handler.\n"); do_exit = false; signal(SIGINT, sighandler); signal(SIGPIPE, sighandler); // Open the data file for output, specifying full path. openfile(); // Loop until signal handler sets 'do_exit' flag on ctrl-c // This exit relates to the completion of the entire measurement // Open a live plot using gnuplot gnuplot_cmd(g, "load '%s'", myfile); while(do_exit == false) { // Open a socket for I/O and subsequent requests/triggers from EMC opensocket(); // We'll wait here for a trigger or message from EMC // This segment is intended for routine data points (not the first) while(1) { temp_sock_descriptor = accept(sock_descriptor, (struct sockaddr *)&pin, &address_size); if (temp_sock_descriptor == -1) { perror("call to accept"); exit(1); } if (recv(temp_sock_descriptor, buf, BUFSIZE, 0) == -1) { perror("call to recv"); exit(1); } printf("received from client:%s\n", buf); // Message received, call up another measurement sequence here. // Read data from DI-194 (this is relatively slow with init each time) opendaq(); readdaq(); di_close(DI_FD); // Update the plot for realtime display gnuplot_cmd(g, "load '%s'", stepfile); // test buf for signal indicating last trigger. if so, exit program // until we get more elegant or readable we presume an "X" is sent // to indicate the end of the process is requested len = strlen(buf); for (i=0; i