msdd6000 source upgraded and enabled
[debian/gnuradio] / gr-msdd6000 / src / msdd_source_simple.cc
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <vector>
6 #include <msdd_source_simple.h>
7 #include <gr_io_signature.h>
8 #include <gr_sync_block.h>
9
10 #ifndef FALSE
11 #define FALSE   (0==1)
12 #define TRUE    (0==0)
13 #endif
14
15
16 msdd_source_simple_sptr
17 msdd_make_source_simple ( const char *src, unsigned short port_src) 
18 {
19   return msdd_source_simple_sptr (new msdd_source_simple ( src, port_src)); 
20 }
21
22
23 msdd_source_simple::msdd_source_simple (
24                     const char *src, 
25                     unsigned short port_src) 
26                 : gr_sync_block("MSDD_SOURCE_SIMPLE",
27                         gr_make_io_signature (0,0,0),
28                         gr_make_io_signature (1, 1, sizeof (short)))
29 {
30         rcv = new MSDD6000((char*)src);
31 }
32
33 int
34 msdd_source_simple::work (int noutput_items,
35                          gr_vector_const_void_star &input_items,
36                          gr_vector_void_star &output_items)
37 {
38         
39 #define BUF_LEN (366*sizeof(short)*2 + 6)
40
41         float* out1 =(float*) output_items[0];
42
43         char buffer[BUF_LEN];
44         rcv->read( &buffer[0], BUF_LEN );
45
46         int seq = *((int*) &buffer[2]);
47         
48         if(d_lastseq == -366){
49                 // not started case
50                 if(seq == 0){
51                         d_lastseq = 0;
52                         } else {
53                         // THROW AWAY SAMPLES WE ARE NOT STARTED YET!
54                         return 0;
55                         }
56                 
57                 } else {
58                 // started case
59                 int samples_missed = seq - d_lastseq - 366;
60                 if(samples_missed > 0){
61                         printf("dropped %d samples.\n", samples_missed);
62                         }
63                 d_lastseq = seq;
64                 }
65         
66         if(noutput_items< 366*2){
67                 printf("NOT ENOUGH SPACE IN OUTPUT BUFFER!!! >:-(\n");
68                 }
69         
70         memcpy(&out1[0], &buffer[6], BUF_LEN - 6);
71         
72 //      for(int i = 0; i < 366*2; i++){
73 //              out1[i] = (float)  (*((short*) &buffer[6+2*i]) );
74 //      }
75         
76         return 366*2;
77 }
78
79 bool msdd_source_simple::set_decim_rate(unsigned int rate)
80 {
81         rcv->set_decim(log2(rate));
82         return TRUE;
83 }
84
85
86 bool msdd_source_simple::set_rx_freq(int channel, double freq)
87 {
88         long new_fc = (long)freq;
89         rcv->set_fc( new_fc/1000000, new_fc%1000000);
90         return TRUE;
91 }
92
93
94 bool msdd_source_simple::set_pga(int which, double gain)
95 {
96         if(gain < 0 || gain > 10){
97                 printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
98                 return FALSE;
99         }
100         // ok i lied this is not really a pga, its decimation gain
101         rcv->set_ddc_gain((int)gain);
102         return TRUE;
103 }
104
105
106 msdd_source_simple::~msdd_source_simple ()
107 {
108         delete rcv;
109 }
110
111
112 bool msdd_source_simple::start()
113 {
114         rcv->start();
115 }
116
117
118 bool msdd_source_simple::stop()
119 {
120         rcv->stop();
121 }
122
123 int msdd_source_simple::ninput_bytes_reqd_for_noutput_items(int out){
124         return 0;
125 }
126
127 long msdd_source_simple::adc_freq(){
128         return 102400000;
129 }
130
131 int msdd_source_simple::decim_rate(){
132         return pow(2, rcv->d_decim);
133 }
134
135
136 std::vector<int> msdd_source_simple::gain_range(){
137         static std::vector<int> r;
138         r.push_back(0);
139         r.push_back(12);
140         return r;
141 }
142
143 std::vector<float> msdd_source_simple::freq_range(){
144         std::vector<float> r;
145         r.push_back(30.0*1000*1000);
146         r.push_back(6.0*1000*1000*1000);
147         return r;
148 }
149