3 * Copyright 2008,2009 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_source_simple.h>
26 #include <gr_io_signature.h>
30 msdd_source_simple_sptr
31 msdd_make_source_simple (const char *src, unsigned short port_src)
33 return msdd_source_simple_sptr (new msdd_source_simple ( src, port_src));
37 msdd_source_simple::msdd_source_simple (const char *src,
38 unsigned short port_src)
39 : gr_sync_block("MSDD_SOURCE_SIMPLE",
40 gr_make_io_signature (0,0,0),
41 gr_make_io_signature (1, 1, sizeof (short))),
42 rcv(new MSDD6000((char*) src)), d_lastseq(0), d_firstrun(true)
44 set_output_multiple(MSDD_COMPLEX_SAMPLES_PER_PACKET*2);
47 msdd_source_simple::~msdd_source_simple ()
53 msdd_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 (MSDD_COMPLEX_SAMPLES_PER_PACKET*sizeof(short)*2 + 6)
60 signed short* out1 =(signed short*) output_items[0];
62 for(int i=0; i<floor(noutput_items*1.0/(2*MSDD_COMPLEX_SAMPLES_PER_PACKET));i++){
64 rcv->read( &buffer[0], BUF_LEN );
66 int seq = *((int*) &buffer[2]);
68 if(d_lastseq == -MSDD_COMPLEX_SAMPLES_PER_PACKET){
73 // THROW AWAY SAMPLES WE ARE NOT STARTED YET!
79 int samples_missed = seq - d_lastseq - MSDD_COMPLEX_SAMPLES_PER_PACKET;
80 if(samples_missed > 0){
81 if(d_firstrun == true){
82 // we may have missed some initial samples off the beginning of
83 // a stream but there are no drop outs in the middle of what we have
85 printf("dropped %d samples.\n", samples_missed);
91 int out_idx = i*MSDD_COMPLEX_SAMPLES_PER_PACKET*2;
92 memcpy(&out1[out_idx], &buffer[6], BUF_LEN - 6);
100 bool msdd_source_simple::set_decim_rate(unsigned int rate)
102 rcv->set_decim((int) floor(log2(rate)));
107 bool msdd_source_simple::set_rx_freq(int channel, double freq)
109 long new_fc = (long)freq;
110 rcv->set_fc( new_fc/1000000, new_fc%1000000);
115 bool msdd_source_simple::set_pga(int which, double gain)
117 if(gain < 0 || gain > 10){
118 printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
121 // ok i lied this is not really a pga, its decimation gain
122 rcv->set_ddc_gain((int)gain);
127 bool msdd_source_simple::start()
134 bool msdd_source_simple::stop()
140 long msdd_source_simple::adc_freq()
145 int msdd_source_simple::decim_rate()
147 return 1 << rcv->d_decim;
151 std::vector<int> msdd_source_simple::gain_range()
153 static std::vector<int> r;
159 std::vector<float> msdd_source_simple::freq_range()
161 std::vector<float> r;
162 r.push_back(30.0*1000*1000);
163 r.push_back(6.0*1000*1000*1000);