/* sendAppl.c user application generating timing information for packet sender programs rtps.o and linuxps depending on the definition of PS_RT_LINUX in pscomm.h */ #include #include "pscomm.h" #define DATA_FILE_SIZE 1000000 #define PACKET_SIZE 50 #define MIN_IAT 0.000025 int main(int argc, char *argv[]) { int i,j, pCount, allDataSent; FILE *datafile = NULL; double rawdata[DATA_FILE_SIZE]; double iat, tsc_count, tsc_time, ratio; int n; //double clockCF = 20000.0/ (20000.0-53.4); float clockCF = 1.0; struct TimeTable tt; ps_init(); // LOAD TEST TIME SERIES FROM FILE if ((argc == 2) || (argc == 4)) { // read data from file datafile = fopen(argv[1], "r"); if (datafile == NULL) { fprintf(stderr,"Error - couldn't open file:%s\n",argv[1]); ps_cleanup(); return 1; } n = fread(rawdata,sizeof(double),DATA_FILE_SIZE, datafile); fprintf(stdout,"%d values read\n",n); for(i = 0; i<10; i++) { fprintf(stdout,"%f\n", rawdata[i]); } if (!feof(datafile)) { fprintf(stderr,"End of file not reached. Only %d values were read.\n",n); } close(datafile); if (argc == 4) { if ( sscanf(argv[2],"%lf",&tsc_count) == 0 ) { fprintf(stderr,"tsc_count should be double\n"); } if ( sscanf(argv[3],"%lf",&tsc_time) == 0 ) { fprintf(stderr,"tsc_time should be double\n"); } fprintf(stdout,"ratio:%.12lf\n", tsc_count/tsc_time); ratio = tsc_count/tsc_time; } else { tsc_count = 1.0; tsc_time = 1.0e-9; ratio = 1e9; } // ps_cleanup(); // return; } pCount = 0; // adding 100 ms to the interarrival time of // first scheduled packet and the initial packet // because the initial packet is usually late // and not to cause unecessary error in timing tt.targetTime[0] = (0.2*tsc_count)/tsc_time; tt.packetSize[0] = PACKET_SIZE; for(i=1; (i < MAX_NUM_OF_PACKETS-1) && (pCount < n); i++) { // converting the interarrival time in rawdata[] given in seconds // to nanoseconds and adding the value to the arrival time of the // previous packet //SALE - changed to be scaled by 1000.0 iat = rawdata[pCount]/1000.0; if (iat < MIN_IAT) { iat = MIN_IAT; } tt.targetTime[i] = tt.targetTime[i-1] + (iat*tsc_count)/tsc_time; tt.packetSize[i] = PACKET_SIZE; pCount++; } //!!! THE LAST ELEMENT IN tt.targetTime MUST BE STOP_SENDING !!! fprintf(stderr,"%i: %Ld\n",i,tt.targetTime[i-1]); tt.targetTime[i] = STOP_SENDING; // First element of the time series sent to the // packet sender module MUST BE NEW_TIME_SERIES tt.targetTime[0] = NEW_TIME_SERIES; /* GENERATING TEST TIME SERIES HERE // generate timing info tt.targetTime[0] = 15000000; tt.packetSize[0] = 300; for(i= 1; i< MAX_NUM_OF_PACKETS; i++) { tt.targetTime[i] = tt.targetTime[i-1] + 20000000; if ( i%2 > 0 ) { tt.targetTime[i] += 0; } tt.packetSize[i] = 300; } tt.targetTime[0] = NEW_TIME_SERIES; for(i= 1; i< MAX_NUM_OF_PACKETS; i++) { tt.targetTime[i] *= clockCF; } //!!! THE LAST ELEMENT IN tt.targetTime MUST BE STOP_SENDING !!! fprintf(stderr,"%i: %Ld\n",i,tt.targetTime[i-1]); tt.targetTime[i-1] = STOP_SENDING; */ // send the packets allDataSent = 0; j = 0; while( allDataSent == 0 ) { if ( ps_send(&tt) == 2 ) { fprintf(stderr,"Late\n"); } if ( pCount < n ) { // Prepare the next tt for sending //sale dodao 1000 iat = rawdata[pCount]/1000.0; if (iat < MIN_IAT) { iat = MIN_IAT; } tt.targetTime[0] = tt.targetTime[i-1] + (iat*tsc_count)/tsc_time ; tt.packetSize[0] = PACKET_SIZE; pCount++; for(i=1; (i < MAX_NUM_OF_PACKETS-1) && (pCount < n); i++) { // converting the interarrival time in rawdata[] given in seconds // to nanoseconds and adding the value to the arrival time of the // previous packet //sale dodao 1000 iat = rawdata[pCount]/1000.0; if (iat < MIN_IAT) { iat = MIN_IAT; } tt.targetTime[i] = tt.targetTime[i-1] + (iat*tsc_count)/tsc_time ; tt.packetSize[i] = PACKET_SIZE; pCount++; } //!!! THE LAST ELEMENT IN tt.targetTime MUST BE STOP_SENDING !!! fprintf(stderr,"%i: %Ld\n",i,tt.targetTime[i-1]); tt.targetTime[i] = STOP_SENDING; } else { allDataSent = 1; } j++; } ps_cleanup(); return 0; }