9 #include <sys/resource.h>
12 #define MSDD_HOST "192.168.1.200"
14 float fc = 3500000000.0;
17 //long target_buf_size = 256*1024*1024; // 2 gig output when converted to floats
18 long target_buf_size = 1024*1024;
19 #define CHUNK_SIZE (366*2)*sizeof(short)+6
20 #define OUTPUT_FILE "CAPTURE_FILE.DAT"
32 int main(int argc, char* argv[]){
34 int prio = getpriority(PRIO_PROCESS, getpid());
35 printf("prio = %d\n", prio);
38 setpriority(PRIO_PROCESS, getpid(), -20);
40 prio = getpriority(PRIO_PROCESS, getpid());
41 printf("new prio = %d\n", prio);
46 // instantiate our reciever instance
47 MSDD6000 rcv((char*)MSDD_HOST);
49 // set up desired rcv parameters
51 int tune_mhz = long(fc)/1000000;
52 int tune_hz = long(fc)%1000000;
53 printf("mhz = %d hz = %d\n", tune_mhz, tune_hz);
56 rcv.set_fc(tune_mhz, tune_hz); // tune frequency in mhz, and ddc fine tuning in hz
57 rcv.set_ddc_gain(gain); // careful, too much gain will cause bit-clipping (this simply chooses which 16 bits to map in 0=high order)
58 rcv.set_rf_attn(10); // adjusted variable attenuator in front of adc (0-32dB i think)
63 // allocate our recieve buffer
65 buffer_size = ((long)CHUNK_SIZE) * (target_buf_size/CHUNK_SIZE);
67 printf("Allocating Intermediate Buffer. %f MB\n", ((float)buffer_size)/(1024.0*1024));
68 buffer = (char*)malloc(buffer_size);
70 printf("malloc returns %x.\n", buffer);
72 while(in_ptr + CHUNK_SIZE < buffer_size){
73 rcv.read( &buffer[in_ptr], CHUNK_SIZE );
84 FILE* fd = fopen(OUTPUT_FILE, "w");
86 for(long long i=0;i<buffer_size;i += CHUNK_SIZE){
87 int seq = *((int*) &buffer[i + 2] );
89 // printf( "seq = %d, lastseq = %d at i = %d\n", seq, lastseq, i);
93 // printf("found start... starting...\n");
97 if(seq != lastseq+366){
98 // printf("seq gap, %d -> %d\n", lastseq, seq);
100 // printf("stopping at i=%d\n", i);
103 // printf("this is a bad discontinuity!!! :{\n");
107 // this is good data, and we are started
108 for(int j = 0; j<366*2; j++){
110 // printf("%x %x \n", buffer[ptr], buffer[ptr+1]);
111 short int sample_data = (*(( signed short*) &buffer[ptr]));
112 // printf("%d\n", sample_data);
113 fbuf[j] = (float) sample_data;
114 // printf("%f\n", fbuf[j]);
117 fwrite(fbuf, sizeof(float), 366*2, fd);
125 printf("total discontinuities = %d\n", discont);