3 * Copyright 2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <msdd_rs_source_simple.h>
26 #include <gr_io_signature.h>
30 msdd_rs_source_simple_sptr
31 msdd_rs_make_source_simple ( const char *src, unsigned short port_src)
33 return msdd_rs_source_simple_sptr (new msdd_rs_source_simple ( src, port_src));
37 msdd_rs_source_simple::msdd_rs_source_simple (
39 unsigned short port_src)
40 : gr_sync_block("MSDD_RS_SOURCE_SIMPLE",
41 gr_make_io_signature (0,0,0),
42 gr_make_io_signature (1, 1, sizeof (short))),
43 rcv(new MSDD6000_RS((char*) src)), d_lastseq(0)
47 msdd_rs_source_simple::~msdd_rs_source_simple ()
53 msdd_rs_source_simple::work (int noutput_items,
54 gr_vector_const_void_star &input_items,
55 gr_vector_void_star &output_items)
58 #define BUF_LEN (366*sizeof(short)*2 + 6)
60 float* out1 =(float*) output_items[0];
63 /* Read a buffer out -- looking at UDP payload at this point.*/
64 rcv->read( &buffer[0], BUF_LEN );
66 int seq = *((int*) &buffer[2]);
67 char type = buffer[0];
68 //printf("Sequence %d\n",seq);
70 // FIXME get rid of these magic 366's!
74 /* Received control packet -- parse and update locally stored parameters */
75 printf("Parsing control Packet\n");
76 rcv->parse_control(&buffer[0], seq);
85 // THROW AWAY SAMPLES WE ARE NOT STARTED YET!
94 /* Received control packet -- parse and update locally stored parameters */
95 printf("Parsing control Packet\n");
96 rcv->parse_control(&buffer[0], seq);
100 int samples_missed = seq - d_lastseq - 366;
101 if(samples_missed > 0)
103 printf("dropped %d samples.\n", samples_missed);
109 if(noutput_items< 366*2){
110 printf("NOT ENOUGH SPACE IN OUTPUT BUFFER!!! >:-(\n");
113 memcpy(&out1[0], &buffer[6], BUF_LEN - 6);
115 // for(int i = 0; i < 366*2; i++){
116 // out1[i] = (float) (*((short*) &buffer[6+2*i]) );
122 //bool msdd_rs_source_simple::set_decim_rate(unsigned int rate)
124 // // FIXME seems buggy. How about a floor or ceil?
125 // rcv->set_decim((int) log2(rate));
129 bool msdd_rs_source_simple::set_rx_freq(double freq)
131 long new_fc = (long)freq;
132 rcv->set_fc( new_fc/1000000, new_fc%1000000);
137 bool msdd_rs_source_simple::set_ddc_gain(double gain)
139 if(gain < 0 || gain > 7){ // only 3 bits available.
140 printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
144 rcv->set_ddc_gain((int)gain);
148 // Set desired sample rate of MSDD6000 -- Note bounds checking is
149 // done by the module and it will return the value actually used in the hardware.
150 bool msdd_rs_source_simple::set_ddc_samp_rate(double rate)
152 rcv->set_ddc_samp_rate((float) rate);
156 // Set desired input BW of MSDD6000 -- Note bounds checking is
157 // done by the module and it will return the value actually used in the hardware.
158 bool msdd_rs_source_simple::set_ddc_bw(double bw)
160 rcv->set_ddc_bw((float) bw);
164 bool msdd_rs_source_simple::set_rf_atten(double rf_atten)
166 rcv->set_rf_attn((int) rf_atten);
170 bool msdd_rs_source_simple::start()
177 bool msdd_rs_source_simple::stop()
183 int msdd_rs_source_simple::start_data()
185 return rcv->start_data();
188 int msdd_rs_source_simple::stop_data()
190 return rcv->stop_data();
193 /* Query functions */
194 long msdd_rs_source_simple::pull_adc_freq(){
198 /* Request the current ddc sample rate */
199 float msdd_rs_source_simple::pull_ddc_samp_rate(){
200 return(rcv->pull_ddc_samp_rate());
203 /* Request the current ddc bandwidth */
204 float msdd_rs_source_simple::pull_ddc_bw(){
205 return(rcv->pull_ddc_bw());
209 /* Request the current rx freq */
210 float msdd_rs_source_simple::pull_rx_freq(){
211 return(rcv->pull_rx_freq());
214 /* Request current ddc gain */
215 int msdd_rs_source_simple::pull_ddc_gain(){
216 return(rcv->pull_ddc_gain());
219 /* Request current RF attenuation */
220 int msdd_rs_source_simple::pull_rf_atten(){
221 return(rcv->pull_rf_atten());
224 std::vector<int> msdd_rs_source_simple::gain_range(){
225 static std::vector<int> r;
231 std::vector<float> msdd_rs_source_simple::freq_range(){
232 std::vector<float> r;
233 r.push_back(30.0*1000*1000);
234 r.push_back(6.0*1000*1000*1000);