#include <values.h>
#include <sched.h>
#include <iostream>
cout<<name<<" : An application to stream input from IIO devices to file."<<endl;
cout<<"Usage:"<<endl;
cout<<"\t "<<name<<" [options] outFileName"<<endl;
cout<<"\t -N : The number of samples to read each time from the IIO devices : (-N"<<N<<")"<<endl;
cout<<"\t -t : The duration to sample for : (-t"<<T<<")"<<endl;
return 0;
}
int main(
int argc,
char *argv[]) {
int targetTime=40;
int i=0;
string help;
if (op.
getArg<
string>(
"h", argc, argv, help, i=0)!=0)
if (op.
getArg<
string>(
"help", argc, argv, help, i=0)!=0)
if (argc<2)
if (op.
getArg<
int>(
"N", argc, argv, N, i=0)!=0)
;
if (op.
getArg<
int>(
"t", argc, argv, targetTime, i=0)!=0)
;
struct sched_param param;
param.sched_priority = 96;
if (sched_setscheduler(0, SCHED_FIFO, & param) == -1) {
perror("sched_setscheduler");
return -1;
}
cout<<"N="<<N<<", M="<<M<<" resulting in a processing time of "<<M*N/1e6<<endl;
string chipName("AD7476A");
exit(ret);
Eigen::Matrix<unsigned short, Eigen::Dynamic, Eigen::Dynamic> dataStore;
dataStore.resize(M*N*2, 2);
Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic> data;
exit(ret);
exit(ret);
struct timespec start, stop, readStart, readStop, cycleDuration, outReadStart, outReadStop;
if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) {
cout<<"clock start get time error"<<endl;
exit(-1);
}
cycleDuration.tv_sec = start.tv_sec;
cycleDuration.tv_nsec = start.tv_nsec;
for (int i=0; i<M; i++) {
usleep(3000);
if( clock_gettime( CLOCK_REALTIME, &readStart) == -1 ) {
cout<<"clock start get time error"<<endl;
exit(-1);
}
double duration = 1.e3*( readStart.tv_sec - readStop.tv_sec ) + (double)( readStart.tv_nsec - readStop.tv_nsec )/1.e6;
cout<<"Outside read duration "<<duration<<" ms\n";
cout<<"error with i="<<i<<" out of M="<<M<<" loops."<<endl;
break;
}
if( clock_gettime( CLOCK_REALTIME, &readStop) == -1 ) {
cout<<"clock start get time error"<<endl;
exit(-1);
}
duration = 1.e3*( readStop.tv_sec - readStart.tv_sec ) + (double)( readStop.tv_nsec - readStart.tv_nsec )/1.e6;
cout<<"Read duration "<<duration<<" ms\n";
duration = 1.e3*( readStop.tv_sec - cycleDuration.tv_sec ) + (double)( readStop.tv_nsec - cycleDuration.tv_nsec )/1.e6;
cout<<"\t\t\t\t\tCycle duration "<<duration<<" ms\n";
cycleDuration.tv_sec = readStop.tv_sec;
cycleDuration.tv_nsec = readStop.tv_nsec;
dataStore.block(i*N*2, 0, N*2, 2)=data;
if( clock_gettime( CLOCK_REALTIME, &readStop) == -1 ) {
cout<<"clock start get time error"<<endl;
exit(-1);
}
}
if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) {
cout<<"clock stop get time error"<<endl;
exit(-1);
}
double duration = 1.e3*( stop.tv_sec - start.tv_sec ) + (double)( stop.tv_nsec - start.tv_nsec )/1.e6;
cout<<"Duration "<<duration<<" ms\n";
double expected = (float)(N*M)/1.e6*1.e3;
cout<<"Expected "<<expected<<" ms\n";
cout<<"Difference "<<duration-expected<<" ms\n";
float fs=1.e6;
ret=sox.
openWrite(argv[argc-1], fs, dataStore.cols(), MAXSHORT);
return ret;
int written=sox.
write(dataStore);
cout<<"output written to "<<argv[argc-1]<<endl;
return 0;
}