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]);
69 memcpy(&seq, &buffer[2], 4*sizeof(char));
71 char type = buffer[0];
72 //printf("Sequence %d\n",seq);
74 // FIXME get rid of these magic 366's!
78 /* Received control packet -- parse and update locally stored parameters */
79 printf("Parsing control Packet\n");
80 rcv->parse_control(&buffer[0], seq);
89 // THROW AWAY SAMPLES WE ARE NOT STARTED YET!
98 /* Received control packet -- parse and update locally stored parameters */
99 printf("Parsing control Packet\n");
100 rcv->parse_control(&buffer[0], seq);
104 int samples_missed = seq - d_lastseq - 366;
105 if(samples_missed > 0)
107 printf("dropped %d samples.\n", samples_missed);
113 if(noutput_items< 366*2){
114 printf("NOT ENOUGH SPACE IN OUTPUT BUFFER!!! >:-(\n");
117 memcpy(&out1[0], &buffer[6], BUF_LEN - 6);
119 // for(int i = 0; i < 366*2; i++){
120 // out1[i] = (float) (*((short*) &buffer[6+2*i]) );
126 //bool msdd_rs_source_simple::set_decim_rate(unsigned int rate)
128 // // FIXME seems buggy. How about a floor or ceil?
129 // rcv->set_decim((int) log2(rate));
133 bool msdd_rs_source_simple::set_rx_freq(double freq)
135 long new_fc = (long)freq;
136 rcv->set_fc( new_fc/1000000, new_fc%1000000);
141 bool msdd_rs_source_simple::set_ddc_gain(double gain)
143 if(gain < 0 || gain > 7){ // only 3 bits available.
144 printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
148 rcv->set_ddc_gain((int)gain);
152 // Set desired sample rate of MSDD6000 -- Note bounds checking is
153 // done by the module and it will return the value actually used in the hardware.
154 bool msdd_rs_source_simple::set_ddc_samp_rate(double rate)
156 rcv->set_ddc_samp_rate((float) rate);
160 // Set desired input BW of MSDD6000 -- Note bounds checking is
161 // done by the module and it will return the value actually used in the hardware.
162 bool msdd_rs_source_simple::set_ddc_bw(double bw)
164 rcv->set_ddc_bw((float) bw);
168 bool msdd_rs_source_simple::set_rf_atten(double rf_atten)
170 rcv->set_rf_attn((int) rf_atten);
174 bool msdd_rs_source_simple::start()
181 bool msdd_rs_source_simple::stop()
187 int msdd_rs_source_simple::start_data()
189 return rcv->start_data();
192 int msdd_rs_source_simple::stop_data()
194 return rcv->stop_data();
197 /* Query functions */
198 long msdd_rs_source_simple::pull_adc_freq(){
202 /* Request the current ddc sample rate */
203 float msdd_rs_source_simple::pull_ddc_samp_rate(){
204 return(rcv->pull_ddc_samp_rate());
207 /* Request the current ddc bandwidth */
208 float msdd_rs_source_simple::pull_ddc_bw(){
209 return(rcv->pull_ddc_bw());
213 /* Request the current rx freq */
214 float msdd_rs_source_simple::pull_rx_freq(){
215 return(rcv->pull_rx_freq());
218 /* Request current ddc gain */
219 int msdd_rs_source_simple::pull_ddc_gain(){
220 return(rcv->pull_ddc_gain());
223 /* Request current RF attenuation */
224 int msdd_rs_source_simple::pull_rf_atten(){
225 return(rcv->pull_rf_atten());
228 std::vector<int> msdd_rs_source_simple::gain_range(){
229 static std::vector<int> r;
235 std::vector<float> msdd_rs_source_simple::freq_range(){
236 std::vector<float> r;
237 r.push_back(30.0*1000*1000);
238 r.push_back(6.0*1000*1000*1000);