/* * * Template for solution to EE 4770, RTS, 1997 Homework 5. * */ #include #include #include /* random should be in the include file but isn't on Solaris. */ long random(void); #define SIZE 1000 /* Number of samples to store. */ /* * Routines below are stubs for interface and timing functions. * */ double get_current_time() { struct timespec tp; /* clock_gettime is part of the Posix library. If it is not available on your system substitute time() or, since the return value isn't really used, comment out completely. */ clock_gettime(CLOCK_REALTIME, &tp); return ((double)tp.tv_sec) + tp.tv_nsec * 1e9; } static int ri_sample_history[SIZE]; static int ri_next_sample = -1; static int ri_delta = SIZE / 2; /* Generate and store random numbers for sensor output. Numbers are stored so that readInterfaceB can generate a time-delayed version. */ int readInterfaceA() { if( ri_next_sample == -1 ){ int i; for(i=0;i 1000 ) printf("Flow velocity %f\n",value); if( count == 1020 )exit(0); } /* * Routine containing main loop and where solution should be placed. * */ void cross_cor() { int samp_A[SIZE]; /* Hold values read from sensor A. */ int samp_B[SIZE]; /* Hold values read from sensor B. */ double next_sample_time; /* Time at which sensors will be read. */ double sample_interval = 0.1; /* Second, time between reading sensors. */ int i; for(i=0;i0; i--){ samp_A[i] = samp_A[i-1]; samp_B[i] = samp_B[i-1]; } /* Store new samples. */ samp_A[0]=a; samp_B[0]=b; /* Code to compute flow velocity. */ /* (The solution starts here.) */ flow_velocity = ???? /* (The solution ends here.) */ /* Display flow velocity. */ display(flow_velocity); /* Function will return at next_sample_time. */ sleep_until( next_sample_time ); } } int main(int argv, char **argc) { cross_cor(); /* Never returns. */ return 0; }