3 * Copyright 2008,2010 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>
31 msdd_rs_source_simple_sptr
32 msdd_rs_make_source_simple ( const char *src, unsigned short port_src)
34 return gnuradio::get_initial_sptr(new msdd_rs_source_simple ( src, port_src));
38 msdd_rs_source_simple::msdd_rs_source_simple (
40 unsigned short port_src)
41 : gr_sync_block("MSDD_RS_SOURCE_SIMPLE",
42 gr_make_io_signature (0,0,0),
43 gr_make_io_signature (1, 1, sizeof (short))),
44 rcv(new MSDD6000_RS((char*) src)), d_lastseq(0)
48 msdd_rs_source_simple::~msdd_rs_source_simple ()
54 msdd_rs_source_simple::work (int noutput_items,
55 gr_vector_const_void_star &input_items,
56 gr_vector_void_star &output_items)
59 #define BUF_LEN (366*sizeof(short)*2 + 6)
61 float* out1 =(float*) output_items[0];
64 /* Read a buffer out -- looking at UDP payload at this point.*/
65 rcv->read( &buffer[0], BUF_LEN );
67 int seq = *((int*) &buffer[2]);
68 char type = buffer[0];
69 //printf("Sequence %d\n",seq);
71 // FIXME get rid of these magic 366's!
75 /* Received control packet -- parse and update locally stored parameters */
76 printf("Parsing control Packet\n");
77 rcv->parse_control(&buffer[0], seq);
86 // THROW AWAY SAMPLES WE ARE NOT STARTED YET!
95 /* Received control packet -- parse and update locally stored parameters */
96 printf("Parsing control Packet\n");
97 rcv->parse_control(&buffer[0], seq);
101 int samples_missed = seq - d_lastseq - 366;
102 if(samples_missed > 0)
104 printf("dropped %d samples.\n", samples_missed);
110 if(noutput_items< 366*2){
111 printf("NOT ENOUGH SPACE IN OUTPUT BUFFER!!! >:-(\n");
114 memcpy(&out1[0], &buffer[6], BUF_LEN - 6);
116 // for(int i = 0; i < 366*2; i++){
117 // out1[i] = (float) (*((short*) &buffer[6+2*i]) );
123 //bool msdd_rs_source_simple::set_decim_rate(unsigned int rate)
125 // // FIXME seems buggy. How about a floor or ceil?
126 // rcv->set_decim((int) log2(rate));
130 bool msdd_rs_source_simple::set_rx_freq(double freq)
132 long new_fc = (long)freq;
133 rcv->set_fc( new_fc/1000000, new_fc%1000000);
138 bool msdd_rs_source_simple::set_ddc_gain(double gain)
140 if(gain < 0 || gain > 7){ // only 3 bits available.
141 printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
145 rcv->set_ddc_gain((int)gain);
149 // Set desired sample rate of MSDD6000 -- Note bounds checking is
150 // done by the module and it will return the value actually used in the hardware.
151 bool msdd_rs_source_simple::set_ddc_samp_rate(double rate)
153 rcv->set_ddc_samp_rate((float) rate);
157 // Set desired input BW of MSDD6000 -- Note bounds checking is
158 // done by the module and it will return the value actually used in the hardware.
159 bool msdd_rs_source_simple::set_ddc_bw(double bw)
161 rcv->set_ddc_bw((float) bw);
165 bool msdd_rs_source_simple::set_rf_atten(double rf_atten)
167 rcv->set_rf_attn((int) rf_atten);
171 bool msdd_rs_source_simple::start()
178 bool msdd_rs_source_simple::stop()
184 int msdd_rs_source_simple::start_data()
186 return rcv->start_data();
189 int msdd_rs_source_simple::stop_data()
191 return rcv->stop_data();
194 /* Query functions */
195 long msdd_rs_source_simple::pull_adc_freq(){
199 /* Request the current ddc sample rate */
200 float msdd_rs_source_simple::pull_ddc_samp_rate(){
201 return(rcv->pull_ddc_samp_rate());
204 /* Request the current ddc bandwidth */
205 float msdd_rs_source_simple::pull_ddc_bw(){
206 return(rcv->pull_ddc_bw());
210 /* Request the current rx freq */
211 float msdd_rs_source_simple::pull_rx_freq(){
212 return(rcv->pull_rx_freq());
215 /* Request current ddc gain */
216 int msdd_rs_source_simple::pull_ddc_gain(){
217 return(rcv->pull_ddc_gain());
220 /* Request current RF attenuation */
221 int msdd_rs_source_simple::pull_rf_atten(){
222 return(rcv->pull_rf_atten());
225 std::vector<int> msdd_rs_source_simple::gain_range(){
226 static std::vector<int> r;
232 std::vector<float> msdd_rs_source_simple::freq_range(){
233 std::vector<float> r;
234 r.push_back(30.0*1000*1000);
235 r.push_back(6.0*1000*1000*1000);