]> git.gag.com Git - debian/gnuradio/blob - gr-msdd6000/src/non_gr_snapshot_tool/client5.cc
Add lookup by serial number.
[debian/gnuradio] / gr-msdd6000 / src / non_gr_snapshot_tool / client5.cc
1 #include "msdd6000.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <pthread.h>
5 #include <semaphore.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/time.h>
9 #include <sys/resource.h>
10
11
12 #define MSDD_HOST       "192.168.1.200"
13 int decim = 2;
14 float fc = 3500000000.0;
15 int gain = 1;
16
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"
21
22 char* buffer;
23 long int buffer_size;
24 sem_t buf_sem;
25 sem_t lock;
26
27 long int in_ptr;
28 long int out_ptr;
29 char** argvg;
30
31
32 int main(int argc, char* argv[]){
33                 
34         int prio = getpriority(PRIO_PROCESS, getpid());
35         printf("prio = %d\n", prio);
36
37         // renice to -20
38         setpriority(PRIO_PROCESS, getpid(), -20);
39
40         prio = getpriority(PRIO_PROCESS, getpid());
41         printf("new prio = %d\n", prio);
42
43         
44         argvg = argv;
45
46         // instantiate our reciever instance
47         MSDD6000 rcv((char*)MSDD_HOST);
48         
49         // set up desired rcv parameters
50         
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);
54         
55         rcv.set_decim(decim);
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)
59         
60         // send start command
61         rcv.start();
62         
63         // allocate our recieve buffer
64
65         buffer_size = ((long)CHUNK_SIZE) * (target_buf_size/CHUNK_SIZE);
66
67         printf("Allocating Intermediate Buffer.  %f MB\n", ((float)buffer_size)/(1024.0*1024));
68         buffer = (char*)malloc(buffer_size);
69         in_ptr = out_ptr = 0;
70         printf("malloc returns %x.\n", buffer);
71         
72         while(in_ptr + CHUNK_SIZE < buffer_size){
73                 rcv.read( &buffer[in_ptr], CHUNK_SIZE );
74                 in_ptr+=CHUNK_SIZE;
75                 }
76         
77         printf("done.\n");
78                 
79         int lastseq = -1;
80         int discont = 0;
81
82         float fbuf[366*2];
83
84         FILE* fd = fopen(OUTPUT_FILE, "w");
85
86         for(long long i=0;i<buffer_size;i += CHUNK_SIZE){
87                 int seq = *((int*) &buffer[i + 2] );
88                 if(seq == 0){
89 //                      printf( "seq = %d, lastseq = %d at i = %d\n", seq, lastseq, i);
90                 }
91                 if(lastseq == -1){
92                         if(seq==0){
93 //                              printf("found start... starting...\n");
94                                 lastseq = seq;
95                         }
96                 } else {
97                         if(seq != lastseq+366){
98 //                              printf("seq gap, %d -> %d\n", lastseq, seq);
99                                 if(seq==0){
100 //                                      printf("stopping at i=%d\n", i);
101                                         break;
102                                         } else {
103 //                                      printf("this is a bad discontinuity!!! :{\n");
104                                         discont++;
105                                         }
106                         } else {
107                                 // this is good data, and we are started
108                                 for(int j = 0; j<366*2; j++){
109                                         long ptr = i+6+j*2;
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]);
115                                         
116                                 }       
117                                 fwrite(fbuf, sizeof(float), 366*2, fd);
118                         }
119                         lastseq = seq;
120                 }
121         }
122
123         fclose(fd);
124         
125         printf("total discontinuities = %d\n", discont);
126         
127 }
128